Djangoids:
Consider this pattern:
product.brand = brand
product.in_stock = True
product.save()
Because business-layer code does that all the time, can we DRY the
code up a little?
def up(model, **kw):
for key, value in kw.iteritems():
model.__dict__[key] = value
model.save()
That provides this:
up(product, brand=brand, in_stock=True)
It indeed looks kewt, but it does not always work. If, for
example, .brand is a model object, then it ain't in the __dict__.
So is there some more clever way to do this? (or does Django already
have it?) hopefully some way that bypasses "eval()", and other tawdry
assaults on an object's private data?
--
Phlip
http://penbird.tumblr.com/
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.