#10150: Make model_to_dict use SortedDict
----------------------------------------------------------+-----------------
Reporter: Rob Hudson <[email protected]> | Owner:
nobody
Status: new | Milestone:
Component: Forms | Version: 1.0
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------------------------+-----------------
Comment (by Rob Hudson <[email protected]>):
More context of why this is useful...
Similar to iterating over fields in a Form or ModelForm, you could use the
model_to_dict method for a template (or email, etc.) like so:
{{{
def profile_detail(request, profile_id):
try:
profile = Profile.objects.get(pk=profile_id)
except Profile.DoesNotExist:
raise Http404
return render_to_response('profiles/detail.html', {
'profile': profile,
'profile_data': model_to_dict(profile, exclude=('last_modified',))
})
}}}
In the template you'd then have something you can iterate:
{{{
<dl>
{% for key, value in profile_data.items %}
<dt>{{ key }}</dt>
<dd>{{ value }}</dd>
{% endfor %}
</dl>
}}}
With model_to_dict not using SortedDict, the items come out in an unknown
order, which isn't useful for this purpose.
I plan on running the test suite to make sure this change doesn't break
any tests, and adding some docs where appropriate.
--
Ticket URL: <http://code.djangoproject.com/ticket/10150#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---