The Great Magnet. What a fool I was to defy him.

Django — Quick Note From IRC: Model Instance to Dictionary

November 21, 2008 · 1 Comment

Truebosko said it well: [530] i must say you are a man of not-so well known django techniques :)


>>>from django.forms.models import model_to_dict
>>>model_to_dict(model_instance)
Out:
{'id': 1,
'name': u'joe'
}

etc.

I’m sure i’ll use it in the future.

Categories: Life

1 response so far ↓

  • Yuji // December 19, 2008 at 7:46 am | Reply

    I said I’m sure I’d use it in the future, and lo and behold I did.

    I used it to populate the context of an email via it’s subscribers.

    context=Context(model_to_dict(subscriber_instance))

Leave a Comment