From the django tutorial
was_published_recently.admin_order_field = 'pub_date'
What is this statement really doing?
The correct way to create a user in Django is to use the create_user function. This will handle the hashing of the password, etc..
Run 'python manage.py migrate' to apply them. Username (leave blank to use 'chatru'): admin Email address: [email protected] Password: Password (again): The password is too similar to the username.
This is in reference to the admin section of django.
In the admin section corresponding to models, each models has a property called list_display
, which control which fields are displayed on the change list (list display of all the objects) page of the admin.
Now, if you wish to change the default sort order for was_published_recently
in the list_display
you can do so by setting the admin_order_field
attribute.
So, in the example:
class Poll(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
You are adding a custom column called was_published_recently
and specifying the sort order to be the database field pub_date
when the "sort" option for the column was_published_recently
is clicked.
You can understand this better by scrolling down to the information pertaining to admin_order_field
in this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With