On 15 juil, 20:14, Suprnaturall <n.her...@gmail.com> wrote:
> Hi,
>
> I'm wondering if like in play or symfony you can develop special
> method for each class/table in the models.py and use them in your
> template.

Of course. A model is "just" a Python class (well, with some "magic"
but...).

> I'm trying few things but it didn't work.
>
> For exemple this is my models.py :
> class Category(models.Model):
>     name = models.CharField(max_length=250)
>
>     def get_short_name():
>                 return name[0,20]
>
> And here my html :
> <div class="name">Desc : {{ category.get_short_name }} </div>
>
> But it don t work, i'v got nothing in the screen.

Set DEBUG and DEBUG_TEMPLATE to True in your settings.py. You should
get a nice traceback.

>
> What the correct way to do stuff like this, i m supposed to make a
> custom tag in order to truncuate the name field ?

Of course not. But you'd better take some time learning Python if you
hope to do anything with Django.

-- 
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