SHARE
TWEET

Untitled

a guest Jun 25th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django import forms
  2.  
  3. class DinnerForm(forms.Form):
  4.     name = forms.CharField(max_length=100)
  5.     text = forms.CharField(max_length=255)
  6.      
  7. class Dinner(models.Model):
  8.     name = models.CharField(max_length=100)
  9.     text = models.CharField(max_length=255)
  10.      
  11. def add_dinner(request):
  12.     if request.method == 'POST':
  13.         form = DinnerForm(request.POST)
  14.         if form.is_valid():
  15.             name = form.cleaned_data['name']
  16.             text = form.cleaned_data['text']
  17.      
  18. ### example
  19. def add_dinner(request):
  20.     if request.method == 'POST':
  21.         form = DinnerForm(request.POST)
  22.         if form.is_valid():
  23.             name = form.cleaned_data['name']
  24.             text = form.cleaned_data['text']
  25.             diner = Dinner.objects.create(
  26.                             name = name,
  27.                             text = text,)
  28.      
  29. def add_dinner(request):
  30.     if request.method == 'POST':
  31.         form = DinnerForm(request.POST)
  32.         if form.is_valid():
  33.             name = form.cleaned_data['name']
  34.             text = form.cleaned_data['text']
  35.             query = Dinner(name = name , text = text)
  36.             query.save()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top