Remove first_name / last_name from admin if missing from model - #512
Remove first_name / last_name from admin if missing from model#512silviogutierrez wants to merge 3 commits into
Conversation
Codecov Report
@@ Coverage Diff @@
## master #512 +/- ##
==========================================
+ Coverage 94.22% 94.24% +0.01%
==========================================
Files 30 30
Lines 900 903 +3
==========================================
+ Hits 848 851 +3
Misses 52 52
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
@silviogutierrez Thanks for this path. As I mention in the issue, overriding the |
| f"actor__{get_user_model().USERNAME_FIELD}", | ||
| ] | ||
| f"actor__{user_model.USERNAME_FIELD}", | ||
| ] + ( |
There was a problem hiding this comment.
How about something like the following, which adds whichever field is available, handling the case where either fist_name or last_name do actually exist
search_fields = [
"timestamp",
"object_repr",
"changes",
f"actor__{get_user_model().USERNAME_FIELD}",
] + [f"actor__{f.name}" for f in get_user_model()._meta.get_fields() if f.name in ["first_name", "last_name"]]
There was a problem hiding this comment.
This is better because includes whatever fields that are available.
Feel free to create a new PR with tests and changelog
|
Hi. Any progress planned for this issue? |
|
The approach of this PR should be changed. BTW, you can create your custom admin inherited from |
Closes #509
This is a "static" approach, which I think is better than overriding
get_search_fields. I believe theget_*methods are for truly dynamic behavior (based on the request, the current user, etc). With this, admin checks will still apply (though not particularly useful).