Re: custom method in models.py

2011-07-15 Thread Kenneth Gonsalves
On Fri, 2011-07-15 at 11:14 -0700, Suprnaturall wrote: > class Category(models.Model): > name = models.CharField(max_length=250) > > def get_short_name(): > return name[0,20] def get_short_name(self) -- regards KG http://lawgon.livejournal.com Coimbatore LUG rox

Re: custom method in models.py

2011-07-15 Thread bruno desthuilliers
On 15 juil, 20:14, Suprnaturall 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

Re: custom method in models.py

2011-07-15 Thread nicolas HERSOG
Oh crap i m feel ashame... Thanx for your help ! On Fri, Jul 15, 2011 at 8:46 PM, Shawn Milochik wrote: > On 07/15/2011 02:14 PM, Suprnaturall wrote: > >> def get_short_name(): >>return name[0,20] >> > > Try this: > def get_short_name(self): > >return self.name[0:20] > > >

Re: custom method in models.py

2011-07-15 Thread Shawn Milochik
On 07/15/2011 02:14 PM, Suprnaturall wrote: def get_short_name(): return name[0,20] Try this: def get_short_name(self): return self.name[0:20] You need 'self' in two places, and I assume you want a string of the first 20 characters rather than a list of the first and

custom method in models.py

2011-07-15 Thread Suprnaturall
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. 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)