Abigger piece of your model would be nice, but arent you missing a "self" in 
that method definition? TypeErrors would fail silently in the templates


-----Mensaje original-----
De: Kevin
Enviados:  06/07/2012 16:37:04
Asunto:  Re: Calling model methods from templates

I should mention this is happening in a loop iterating over a list of 
objects from my view -- the same object type where the fcnTrue method is 
defined. So I'm actually doing the following in a loop

{% if varTrue %} varTrue = true {% endif %}<br />
{% if fcnTrue %} *myObj*.fcnTrue = true {% endif %}<br />

(I realize the method must be called on an instance, and that's what I'm 
doing but failed to illustrate in my first post)

On Friday, July 6, 2012 2:26:22 PM UTC-5, Kevin wrote:
>
> I'm fairly new to Django/Python so please bear with me.
>
> I want to create some methods in my models that return boolean values 
> (has_employees, etc) but I cannot seem to access the return value in the 
> template.
>
> Here's a cut-down example:
>
> Model:
>
>     def fcnTrue():
>         return True
>
> View:
>
>     return render_to_response('myapp/test.html',
>                               { 'varTrue' : True})
>
> Template:
>
> {% if varTrue %} varTrue = true {% endif %}<br />
> {% if fcnTrue %} fcnTrue = true {% endif %}<br />
>
> Expected output:
>
> varTrue = true
> fcnTrue = true
>
> Actual output:
>
> varTrue = true
>
> What am I doing wrong?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_MWnTbiH4LIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to