Opened 6 years ago
Last modified 2 years 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 )
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 , 6 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 site → Support the use of boolean attribute on properties in the admin. |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → New feature |
| Version: | 3.0 → master |
Note:
See TracTickets
for help on using tickets.
Thanks. This is definitely a new feature (see similar ticket #30259 for
admin_order_fieldsupport). We can support it but when using theproperty()function and not with decorator, that's why I updated the ticket description.