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 at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to