Re: Proper approach to updating model object with 100 attributes.

2010-06-30 Thread Ray Cote
o: "Django users" <django-users@googlegroups.com> Sent: Wednesday, June 30, 2010 10:01:11 AM GMT -05:00 US/Canada Eastern Subject: Re: Proper approach to updating model object with 100 attributes. -- You received this message because you are subscribed to the Google Groups "Djang

Re: Proper approach to updating model object with 100 attributes.

2010-06-30 Thread euan.godd...@googlemail.com
The frozenset wasn't any commentary on your approach or speed of parsing, I just like to use them where-ever possible. My only concern with your approach was that you were expecting every field on the model to be in the dictionary. Looping over the dictionary's items and ignoring any fields that

Re: Proper approach to updating model object with 100 attributes.

2010-06-30 Thread Tim Chase
I'd stick to setattr and maybe verify that the key in the dictionary is one of the model's fields. I think there is a method on _meta called get_all_field_names. I've used this before to validate such actions. If that's the case, you can tweak the above to something like for name in

Re: Proper approach to updating model object with 100 attributes.

2010-06-30 Thread euan.godd...@googlemail.com
I'd probably be a bit more cautious, since get_all_field_names gets foreign keys and all sorts and the field might not be in the dictionary. I'd suggest: # Make a frozenset of the fields for fast access: allowed_fields = frozenset(obj._meta.get_all_field_names()) for field, value in

Re: Proper approach to updating model object with 100 attributes.

2010-06-30 Thread Tim Chase
On 06/30/2010 02:10 AM, euan.godd...@googlemail.com wrote: I think you need to be careful messing with __dict__ as Django turns most fields in descriptors behind the scenes so setting them in the __dict__ could break these. Yeah, that was somewhat my assumption (and thus my caveat). Well,

Re: Proper approach to updating model object with 100 attributes.

2010-06-30 Thread euan.godd...@googlemail.com
I think you need to be careful messing with __dict__ as Django turns most fields in descriptors behind the scenes so setting them in the __dict__ could break these. I'd stick to setattr and maybe verify that the key in the dictionary is one of the model's fields. I think there is a method on

Re: Proper approach to updating model object with 100 attributes.

2010-06-29 Thread Lora
"Ray Cote"<rgac...@appropriatesolutions.com> Sent: Tuesday, June 29, 2010 2:03:05 PM GMT -05:00 US/Canada Eastern Subject: Re: Proper approach to updating model object with 100 attributes. On 06/29/2010 12:01 PM, Ray Cote wrote: Hi List: I have a Django model with over 100 fields in it

Re: Proper approach to updating model object with 100 attributes.

2010-06-29 Thread Ray Cote
esolutions.com> Sent: Tuesday, June 29, 2010 2:03:05 PM GMT -05:00 US/Canada Eastern Subject: Re: Proper approach to updating model object with 100 attributes. On 06/29/2010 12:01 PM, Ray Cote wrote: > Hi List: > > I have a Django model with over 100 fields in it that is loaded from a

Re: Proper approach to updating model object with 100 attributes.

2010-06-29 Thread Tim Chase
On 06/29/2010 12:01 PM, Ray Cote wrote: 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