如何将数据添加到我的数据库?
我的表格:
from django import forms
class DinnerForm(forms.Form):
name = forms.CharField(max_length=100)
text = forms.CharField(max_length=255)
和型号:
class Dinner(models.Model):
name = models.CharField(max_length=100)
text = models.CharField(max_length=255)
我的观点:
def add_dinner(request):
if request.method == 'POST':
form = DinnerForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
text = form.cleaned_data['text']
如何将我的数据保存到数据库中?