0

I have a Django application where users have additional data. That data is collected in a Profile model with a OneToOneField pointing to User.

This is fine and works perfectly for most purposes, but I have trouble customizing the admin for User. In particular:

  • I would like to be able to show a Profile field inside list_display. I don't know how to do this without writing an additional method on User itself.
  • I would like to be able to show some information about related models (e.g. some resources owned by the user) inside the User detail page. Again, I do not know how to do this without writing a custom User method.

Do you know any solution to the above?

2 Answers 2

1

You only have to edit the admin classes in admin.py. You can use admin.inline* class to help you. Example from Django website that will add Book to the Author's admin page:

class BookInline(admin.TabularInline):
    model = Book

class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        BookInline,
    ]

admin.site.register(Author, AuthorAdmin)

Read more here.

EDIT: You should be able to add methods on UserAdmin model and refer to them when setting the list_display fields:

list_display = (..., 'your_method')
Sign up to request clarification or add additional context in comments.

6 Comments

This does not help with the question. Adding an inline does not change the way the list of users is displayed
As for the second point, I need a single field that summarizes some status, not a separate inline.
By the way, the problem was that the model I am working with is User, over which I have no control. I had no problems customizing the admins for other models.
Maybe I was understanding this sentence wrong: ..some information about related models inside the User detail page. I added point about list_display that might help you.
Yes, indeed that is exactly my own answer :-) I removed my downvote
|
0

Turns out, one can put the methods in the UserAdmin itself instead than in the User model. This way I can access all the information I need about the user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.