Django — Quick Note From IRC: Model Instance to Dictionary

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.

2 thoughts on “Django — Quick Note From IRC: Model Instance to Dictionary

  1. 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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s