I want to update only specific fields in a model and keep the old values in 
other fields. I've been working on this for a few days but I run out of 
possible solutions.As far as I can see from the documentation and internet 
 there isn't an easy solution to do this.  I'm new at Django, so I might 
overlook the obvious.  

Ticket https://code.djangoproject.com/ticket/4102 seems to indicate that 
this is an issue. I'm too inexperienced with django to try patching it and I 
prefer another way using standard Django 1.3

I've tried the following:

* .add() only inserts the new data and existing fields are overwritten and 
'NULL' in the database
* do it through .update() in query using the following procedure and pseudo 
code.
1. the id of the record is not known. Create a queryset .objects.all() and 
store all id's as values in a dictionary with another unique in the model as 
a key to retrieve the matching id. At first I used the other unique 
CharField as a PK, but that gave errors in Postgres
2. Using the samples in the query-documentation. Create another query to get 
a single object in a queryset using:
n = SomeModel.objects.get(id=myid)
Somemodel.objects.filter(pk=n).update(somefield=newfielddata)
m.save()
This creates errors, so that doesn't work either.

I was thinking to try a different approach. When a record exists, retrieve 
all existing data and add this to the .save(). This seems like a pretty 
cumbersome way to achieve updating a few fields. What is the best way to 
achieve this?






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/9zf4wZZ0VdsJ.
To post to this group, send email to django-users@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