سؤال

I wanted to know if there was a way of ordering the Django users on the django admin page based on creation time rather than alphabetical order. To be honest, it can be ordered by creation time or the id. But the order needs to be from latest users to the oldest.

I've done some research about ordering objects on the Admin page. I saw one source mentioning date hierarchy. Problem is I don't know the specific field to which the Django User can be ordered by.

Do you have any solutions?

Thanks

هل كانت مفيدة؟

المحلول

Shouldn't it just be:

ordering = ['-date_joined']

You can order by any field the model gives you. Since you didn't specify the UserModel you are using, I guess you are talking about the BaseUser? If so, you can order by:

  • first_name
  • last_name
  • id
  • email
  • date_joined
  • username
  • [is_staff] # bool
  • [is_active] # bool
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top