Tuesday, June 29, 2010

Proper approach to updating model object with 100 attributes.

Hi List:

I have a Django model with over 100 fields in it that is loaded from a data feed.
Each row in the model has a unique field, let's call it item_id.
When loading new data, I'm first checking to see if item_id is in the table,
if it is, I want to update it with the new data from the new 100 fields.

To date, I've done things like:

obj = Model.objects.get(item_id = item_id_from_field)

and then.
obj.field1 = new_field1
etc.

However, for 100 fields, I'd like to find something a bit cleaner than listing 100 fieldnames.
The data for the new 100 fields is in a nice dictionary.

When I create a new item, I'm able to do this:
obj = MyModel(**dictionary_of_field_values)

Is there something similar I can do with my obj once the data is retrieved?

Thanks
--Ray

--
Ray Cote, President
Appropriate Solutions, Inc.
We Build Software
603.924.6079

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

No comments:

Post a Comment