Re: list_display with a function

2010-12-01 Thread Daniel Roseman
On Dec 1, 11:17 am, Daniel Carvalho  wrote:
> hi
>
> I have a model that defines a function:
>
> class Test(models.Model):
>     name = models.CharField(max_length=200)
>
>     data_expira = models.DateField()
>
>     def expired(self):
>         return self.data_expira < datetime.date.today()
>
>     expired.short_description = 'Expirou?'
>
> I want to put it in list_display for this model:
> list_display = ["name", "expired"]
>
> BUT
> django admin displays it as a text, "True" or "False"...
>
> can I tell django that it is a boolean field?

>From the admin docs:
"If the string given is a method of the model, ModelAdmin or a
callable that returns True or False Django will display a pretty "on"
or "off" icon if you give the method a boolean attribute whose value
is True."

So just do `expired.boolean = True` underneath the existing
short_description declaration.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



list_display with a function

2010-12-01 Thread Daniel Carvalho
hi

I have a model that defines a function:

class Test(models.Model):
name = models.CharField(max_length=200)

data_expira = models.DateField()

def expired(self):
return self.data_expira < datetime.date.today()

expired.short_description = 'Expirou?'


I want to put it in list_display for this model:
list_display = ["name", "expired"]

BUT
django admin displays it as a text, "True" or "False"...

can I tell django that it is a boolean field?






signature.asc
Description: OpenPGP digital signature