Using model classes in templates #16307

40 views
Skip to first unread message

Philippe Raoult

unread,
Nov 28, 2013, 5:20:32 AM11/28/13
to django-d...@googlegroups.com
Hello all,

I've had some troubles with default callables in FKs and tracked it down to one of my templates tags which returns a model class. I'm not sure if this is considered kosher or not so feel free comment on that too.

In my template I have a something like:

{{ my_project_lookup_class.classname.get_verbose_name }}

my_project_lookup_class.classname will the return the django model class, and the template engine apparently checks if the class is callable, then calls it which will try to instanciate a new object with no arguments. In that specific case it fails because of missing default values but my intent was to call a classmethod anyway. I worked around it by using the do_not_call_in_templates flag on my models, because I'll never intend to call a constructor from a template anyway.

I've found a ticket corresponding to this issue.
https://code.djangoproject.com/ticket/16307

and here's the discussion regarding the do_not_call_in_templates flag:
https://code.djangoproject.com/ticket/15791

So my question is, would it make sense to make do_not_call_in_templates default to True for django's Model class ?
This would potentially break stuff if people used that trick to actually instantiate objects, I have no idea whether this is a common use case or not.


Reply all
Reply to author
Forward
0 new messages