Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 1, 2010 11:17:22

Daniel C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

list_display with a function


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 =

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

can I tell django that it is a boolean field?signature.ascDescription:OpenPGP digital signature

Attachments:
attachment signature.asc (554 bytes)

Offline

#2 Dec. 1, 2010 11:44:46

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

list_display with a function


On Dec 1, 11:17 am, Daniel Carvalho <idn...@gmail.com> 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 =
>
> 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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 13th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support