Thank you so much for the clarification!
On Friday, July 13, 2012 5:24:18 PM UTC-4, Jani Tiainen wrote:
>
> You still need to call result.is_valid() since it actually runs actual
> validation rules.
>
> Very basic form processing is usually done like this:
>
> so in case of GET you return empty form. in case of invalid POST you
> return form with values and error messages.
>
> After successful POST you do redirect-after-post to avoid problems with
> browser history back-button.
>
> def form_view(request):
> if request.method == 'POST':
> form = MyForm(request.POST)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect("/some/result/form")
> else:
> form = MyForm()
> return HttpResponse("form/form.html", { 'form': form })
>
> On Thu, Jul 12, 2012 at 4:44 AM, JJ Zolper <[email protected]> wrote:
>
>> I was able to make it work!
>>
>> from django.core.context_processors import csrf
>> from django.template import RequestContext
>> from django.http import HttpResponseRedirect
>> from django.http import HttpResponse
>> from django.shortcuts import render_to_response
>> from MadTrak.manageabout.models import AboutMadtrak, AboutMadtrakForm
>>
>> def about(request):
>> AboutMadtrakInstance = AboutMadtrak()
>> result = AboutMadtrakForm(request.POST, instance=AboutMadtrakInstance)
>> result.save()
>> return HttpResponse('It worked?!? Of course it did. I knew that.')
>>
>> def about_form(request):
>> return render_to_response('about_form.html', context_instance =
>> RequestContext(request))
>>
>> I ended up looking at ModelForms and trying that since I was having
>> issues.
>>
>> So does this method handle all validation and security issues for me?
>>
>> Or do I still need a "result.is_valid()" among other things?
>>
>>
>> On Wednesday, July 11, 2012 11:51:19 AM UTC-4, Andre Schemschat wrote:
>>>
>>> Hey,
>>>>>
>>>>
>>> yeah, it basicly is. Just a very, very basic example (And sorry if i
>>> could highlight this as code, i didnt find something in the format-menu :/
>>> ).
>>> Of course you should validate your input first. And if you just want to
>>> edit a Model within a form, you should check on the ModelForm-Class
>>> https://docs.**djangoproject.com/en/dev/**topics/forms/modelforms/<https://docs.djangoproject.com/en/dev/topics/forms/modelforms/>
>>>
>>> def vote(request, poll_id):
>>> try:
>>> obj = YourModel.objects.get(pk=poll_**id)
>>> obj.attributea = request.POST['attributea']
>>> obj.attributeb = request.POST['attributeb']
>>> obj.save()
>>> return HttpResponse(validparamshere)
>>> except ObjectDoesNotExist:
>>> return HttpResponse(show_some_error)
>>>
>>>
>>>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/JTdViX4I6HEJ.
>>
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/_yuwhnXo7ssJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.