Opened 5 years ago

Last modified 15 months ago

#31558 closed New feature

Support the use of boolean attribute on properties in the admin. — at Version 1

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 (last modified by Mariusz Felisiak)

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

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

    was_published_recently.admin_order_field = 'publication_date'
    was_published_recently.short_description = 'Published Recently?'
    was_published_recently.boolean = True
    was_published_recently = property(was_published_recently)

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 (1)

comment:1 by Mariusz Felisiak, 5 years ago

Description: modified (diff)
Summary: Boolean attribute for a property getter of a model doesn’t active the “on/off” icon in the admin siteSupport the use of boolean attribute on properties in the admin.
Triage Stage: UnreviewedAccepted
Type: BugNew feature
Version: 3.0master

Thanks. This is definitely a new feature (see similar ticket #30259 for admin_order_field support). We can support it but when using the property() function and not with decorator, that's why I updated the ticket description.

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