Ejemplo n.º 1
0
 def post(self, request):
     form = FooForm(request.POST)
     if form.is_valid():
         name = form.cleaned_data['name']
         bar_name = form.cleaned_data['bar_name']
         new_foo = Foo.objects.create(name=name)
         if bar_name != None and bar_name !='':
             Bar.objects.create(foo=new_foo, name=bar_name)
         return HttpResponseRedirect(reverse('crud.foo.list'))
     return HttpResponseRedirect('/')
Ejemplo n.º 2
0
 def post(self, request,id):
     form = FooForm(request.POST)
     if form.is_valid():
         name = form.cleaned_data['name']
         bar_name = form.cleaned_data['bar_name']
         object = Foo.objects.get(id=id)
         object.name = name
         object.save()
         if bar_name != None and bar_name !='':
             Bar.objects.create(foo=object, name=bar_name)
         return HttpResponseRedirect(reverse('crud.foo.list'))
     return HttpResponseRedirect('/')