#18548: View changes field when 'unique_together' is not satisfied in a Form
---------------------------+--------------------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+--------------------------------------
Changes (by aaugustin):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> I have a Model called Person with the following constraint:
> unique_together = ('name', 'country')
>
> Furthermore I have a view to to edit a Person:
>
> ----------------------
> def edit_climbing_place(request, person_id):
>
> person = get_object_or_404(Person, pk=person_id)
>
> print person.name
>
> if not request.method == 'POST':
> form = Person(instance=place)
>
> else:
> form = Person(request.POST, instance=place)
>
> if form.is_valid():
> form.save()
> return HttpResponseRedirect(reverse(start_page))
>
> print person.name
>
> return render_to_response('myProject/edit_person.html', {'form' :
> form, 'person': person}, context_instance=RequestContext(request))
> ------------------
>
> In the above code if form.is_valid() fails due to the 'unique_together'
> constraint is not satisfied then the two 'print person.name' outputs are
> different. In other words if I edit an existing 'Person' (say A) and
> change the name to a name which matches an already existing person (say
> B) in the same 'country' then in the above view the variable
> 'person.name' changes to that of B. All other fields, however, stay the
> same.
New description:
I have a Model called Person with the following constraint:
unique_together = ('name', 'country')
Furthermore I have a view to to edit a Person:
{{{
def edit_climbing_place(request, person_id):
person = get_object_or_404(Person, pk=person_id)
print person.name
if not request.method == 'POST':
form = Person(instance=place)
else:
form = Person(request.POST, instance=place)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse(start_page))
print person.name
return render_to_response('myProject/edit_person.html',
{'form' : form, 'person': person},
context_instance=RequestContext(request))
}}}
In the above code if form.is_valid() fails due to the 'unique_together'
constraint is not satisfied then the two 'print person.name' outputs are
different. In other words if I edit an existing 'Person' (say A) and
change the name to a name which matches an already existing person (say B)
in the same 'country' then in the above view the variable 'person.name'
changes to that of B. All other fields, however, stay the same.
--
Comment:
Fixed formatting (please use preview).
--
Ticket URL: <https://code.djangoproject.com/ticket/18548#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
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-updates?hl=en.