Opened 5 years ago

Last modified 15 months ago

#31558 closed New feature

Boolean attribute for a property getter of a model doesn’t active the “on/off” icon in the admin site — at Initial Version

Reported by: Alexandre Poitevin Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Hasan Ramezani Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Example (adapted from the polls tutorial):

class Question(models.Model):

    DEFINITION_OF_RECENT = {"days": 1}

    text = models.CharField(max_length=255)
    publication_date = models.DateTimeField('Date of publication')

    @property
    def was_published_recently(self):
        timenow = timezone.now()
        recent = timenow - timedelta(**self.DEFINITION_OF_RECENT)
        return recent <= self.publication_date <= timenow

    was_published_recently.fget.admin_order_field = 'publication_date'
    was_published_recently.fget.short_description = 'Published Recently?'
    was_published_recently.fget.boolean = True

There is no problem with short_description nor admin_order_filed, but boolean does not act as expected.

(I hesitated between Bug and New feature for this ticket…)

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top