1. Doing Person.save() will NOT update every field in your model.

2. Your snippet uses a ModelForm. Mine used a Form. There's a huge difference.
If you use a ModelForm you're going to have to exclude all the fields you don't 
want.

3. If you use a ModelForm and instantiate it with request.POST, don't send an 
argument
for 'instance' as well. One or the other.

Look at my example again. It does exactly what you want. 
It seems that all your problems are due to not understanding the difference 
between a Form and a ModelForm.

Read the Django book ("The Definitive Guide"). 

Shawn





On Mar 4, 2010, at 1:29 PM, Ken wrote:

> Thanks Shawn
> 
> My problem is that Person.save() will do an update of all my columns.
> Even though they are all identical, apart from the changed value, this
> will violate my minimum privileges requirement of only allowing the
> application access to the columns that it is allowed to change - hence
> your original suggestion of using ModelForms (and only specified
> fields).
> 
> Maybe if I try something like this...
> 
> 
> #Use a ModelForm for Person..
> class PersonForm(forms.ModelForm):
>    model=Person
>    fields = ('age')
> 
> #When the user submits the form:
> person = Person.objects.get(pk = 123)
> person_form = PersonForm(request.POST, instance = person)
> if person_form.is_valid()
>        person_form.save()
> 
> Would that work...?  I'll attempt to hack an example in my code and
> tell you what happens...
> 
> Thanks for your time...
> 
> Ken
> 
> 
> On 4 Mar, 17:28, Shawn Milochik <sh...@milochik.com> wrote:
>> Here's a simple example. It could be improved, but it's meant to be very 
>> simple.
>> 
>> #Make a simple form.
>> 
>> class AgeForm(forms.Form):
>>     age = forms.IntegerField()
>> 
>> #When the user submits the form:
>> 
>> age_form = AgeForm(request.POST)
>> 
>> if age_form.is_valid()
>> 
>>         #get the pk however you need to
>>         person = Person.objects.get(pk = 123)
>>         person.age = age_form.cleaned_data['age']
>>         person.save()
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to