Thanks

Unfortunately I'm very new to Forms/ModelForms, and I'm having a lot
of difficulty understanding the Django examples.

All I want is to allow my users to make one change to one column.  I
don't want them to see the ID, just a text box and a submit button.
Hitting Submit should take them back to exactly the same page, with
the text field pre-populated to what they entered.

The database update should only change one column of the relevant row
in the database table.

This would take 30 seconds to do in PHP.

Can anyone point me to some simple examples (other than the Django
site).

Cheers,

Ken


On 3 Mar, 00:31, Shawn Milochik <sh...@milochik.com> wrote:
> Use a forms.ModelForm and exclude all the fields except one, or use a  
> forms.Form with one field and use its value in a queryset .update()  
> call.
>
> Shawn
>
> Sent from my iPhone
>
> On Mar 2, 2010, at 7:11 PM, Ken <ken.w.sm...@gmail.com> wrote:
>
>
>
> > Folks
>
> > This is a bit of a newbie question on Model updates.  I've been
> > happily using Django to give my users a read-only view of the database
> > for nearly a year, but now I'd like my users to be able to update a
> > row in one of my tables.
>
> > We're told in the Model documentation that "Django knows best" when it
> > comes to talking to the database.
>
> > However, I want my users to ONLY update ONE column in one row in my
> > database, but Django seems to insist on updating all the columns.  (A
> > related problem is that I'd also like the database user only to be
> > allowed to update a subset of columns of my table - mostly because I'm
> > paranoid.)
>
> > If you don't specify the column value, and the column is nullable, the
> > unspecified columns get set to NULL instead of left alone.
>
> > Here's an example...
>
> > select * from tcs_detection_lists;
> > +----+-----------+---------------------+
> > | id | name      | description         |
> > +----+-----------+---------------------+
> > |  0 | garbage   | Bad Candidates      |
> > |  1 | confirmed | Confirmed SNe       |
> > |  2 | good      | Good Candidates     |
> > |  3 | possible  | Possible Candidates |
> > |  4 | pending   | Not Yet Eyeballed   |
> > +----+-----------+---------------------+
>
> > I want to update the word 'garbage' to 'bad'.
>
> > Here's my simplistic Django code...
>
> > dl = views.TcsDetectionLists(id=0, name ='bad')
> > dl.save()
>
> > select * from tcs_detection_lists;
> > +----+-----------+---------------------+
> > | id | name      | description         |
> > +----+-----------+---------------------+
> > |  0 | bad       |                     |
> > |  1 | confirmed | Confirmed SNe       |
> > |  2 | good      | Good Candidates     |
> > |  3 | possible  | Possible Candidates |
> > |  4 | pending   | Not Yet Eyeballed   |
> > +----+-----------+---------------------+
>
> > I only wanted the user to change one column, but Django has assumed
> > None for the rest of the columns and therefore deleted my
> > 'description' field.
>
> > The update that I want is:
>
> > update tcs_detection_lists
> > set name = 'bad'
> > where id = 0;
>
> > Note that some of my tables have many columns (>50) with a lot of
> > floating point data and I certainly don't want my users inadvertently
> > deleting data.
>
> > Do I need to specify something in my Model columns to get Django to
> > behave the way I want it to...?  I really don't want to have to resort
> > to a bit of custom SQL...
>
> > Thanks in advance,
>
> > Ken
>
> > --
> > 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 
> > athttp://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