tags:

views:

22

answers:

1

Something like

my_model.data_dict['my_field']

Which would give you the current value for that field? Need something like that to interface with my other code.

+1  A: 

It's lil tricky but you can do it like this:

def model2dict(obj):
   return dict([(field, getattr(obj, field)) for field in obj._meta.get_all_field_names()])

So you can access values:

model2dict(my_model)['my_field']
Andrey Gubarev
Does that mean "no, they don't such an attribute"?
Mark
i think the answer is "yes"
Andrey Gubarev