Re: multiple forms for same model
You'll want to call is_valid() only if the request.method is "POST",
plus your code leaves the possibility of an error if none of those
permissions is found (your elif should probably simply be an else?).
On Aug 16, 6:49 am, Mess <bauerna...@gmail.com> wrote:
> Hi,
>
> I have a model where different users should have different
> possibilities to edit, i.e. admin should be able to edit everything,
> but users should only be able to edit certain fields.
>
> My problem is that the user form doesn't validate when submitting
> update as a user. But I get the error that the fields are missing even
> though I can see them redisplayed.
>
> I am looking at this tutorial:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a...
> And I don't get what is different in my example since I pass "instance
> = c" which contains the missing fields.
>
> def update_contract(request,c):
> if request.user.has_perm("contracts.is_admin") or
> request.user.has_perm("contracts.is_internal"):
> contract_form = ContractForm(request.POST, instance = c)
> elif
> request.user.has_perm("contracts.is_external"):
> contract_form = ContractFormExternal(request.POST,
> instance = c)
> if contract_form.is_valid():
> contract_form.save()
> return view_contract_details(request, c.pk, True)
> else:
> return render_to_response('contracts/
> view_contract_details.html', {
> 'info_message' : 'Please correct the data in the
> form',
> 'contract_form': contract_form,
> 'contract_id' : c.pk,
> },context_instance=RequestContext(request))
>
> Anyone can hint as to where it goes wrong or a hint to how to better
> accomplish this?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home