Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document or remove first_name / last_name as a search in the admin for custom users #509

Open
silviogutierrez opened this issue Feb 9, 2023 · 2 comments · May be fixed by #512
Open

Document or remove first_name / last_name as a search in the admin for custom users #509

silviogutierrez opened this issue Feb 9, 2023 · 2 comments · May be fixed by #512

Comments

@silviogutierrez
Copy link

silviogutierrez commented Feb 9, 2023

If you use a custom user that does not include first_name / last_name as a field, searching in the admin will error out as actor__first_name and actor__last_name are not valid fields.

I can think of a few options:

  1. Unregister the admin using admin.site.unregister(LogEntry)
  2. Subclass LogEntryAdmin, override search_fields
  3. Register this new admin.

Or simply remove these fields from the built-in admin search_fields.

Or only add these to search if get_user_model + meta ensures they exist.

I generally avoid splitting up first name / last name these days, though I know Django defaults to this.

Let me know which option sounds reasonable and I'm happy to open a PR. Great project, saved me a lot of time. Thanks.

@silviogutierrez silviogutierrez changed the title Document or remove first_name / last_name as a search in the admin Document or remove first_name / last_name as a search in the admin for custom users Feb 9, 2023
@aleh-rymasheuski
Copy link
Contributor

@silviogutierrez, the option to ensure that first_name & last_name fields exists makes the most sense to me. I think we can define get_search_fields method on LogEntryAdmin which will inspect the user model and exclude any of the two fields if they are not defined.

@hramezani
Copy link
Member

Thanks @silviogutierrez for the issue.
Agree with @alieh-rymasheuski, get_search_fields sounds good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants