models py class Menu models Model title models CharField maxlength 20

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#models.py
class Menu(models.Model):
title = models.CharField(maxlength=20)
content = models.TextField()
side = models.CharField(maxlength=10,choices=(('left','left'),('right','right')))
page = models.ForeignKey('Page')
def __str__(self):
return self.title
#view
def contact(request):
if request.method == 'POST':
form = form_for_model(request.POST)
if form.is_valid():
form.save()
return render_to_response('detail.html',)
else:
form = form_for_model(Menu)()
return render_to_response('contact.html', {'form': form})