#31558: Support the use of boolean attribute on properties in the admin.
-------------------------------------+-------------------------------------
Reporter: Alexandre Poitevin | Owner: Alexandre
| Poitevin
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Alexandre Poitevin):
Setting a variable function is already what you find in the tutorial…
{{{
class Question(models.Model):
# ...
def was_published_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date <= now
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
}}}
See: https://docs.djangoproject.com/en/3.0/intro/tutorial07/#id8
And in https://docs.djangoproject.com/en/3.0/ref/contrib/admin/ :
> Elements of list_display can also be properties. Please note however,
that due to the way properties work in Python, setting short_description
or admin_order_field on a property is only possible when using the
property() function and not with the @property decorator.
>
> For example:
{{{
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
def my_property(self):
return self.first_name + ' ' + self.last_name
my_property.short_description = "Full name of the person"
my_property.admin_order_field = 'last_name'
full_name = property(my_property)
class PersonAdmin(admin.ModelAdmin):
list_display = ('full_name',)
}}}
End of citation.
And this is what I was referring earlier. You can’t set the attribute on
property, but you can set it to its `fget`. There’s no problem about using
the decorator. We just have do update this part of the documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/31558#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.1e50b73217c53e97530dd3dc3d6e8527%40djangoproject.com.