django-search-admin-autocomplete
django-search-admin-autocomplete copied to clipboard
Refactor as Mixin
Just a small suggestion.
Maybe you could refactor your admin class to be used as a Mixin rather than as BaseClass. Like DjangoQl does. So instead of writing
class MyModelAdmin(SearchAutoCompleteAdmin)
search_fields = ['search_field', ]
you'd write
class MyModelAdmin(SearchAutoCompleteMixin, admin.ModelAdmin)
search_fields = ['search_field', ]
That way your functionality could probably also be used when using other admin extensions (e.g. [django-nested-admin])(https://pypi.org/project/django-nested-admin/).
I know, multiple inheritance is a controversial topic. But in Django its used all the time (see class based views) so why not use it here?
Correct me, if I'm wrong, but I think the only thing needed for this would be to simply drop the inheritance from this line
from class SearchAutoCompleteAdmin(admin.ModelAdmin):
to class SearchAutoCompleteAdmin:
.
And maybe a custom error message on this classes __init__
if it gets used without importing admin.
Tell me, what you think :)
I went ahead and forked this repo to test this. Seems to work just fine: https://github.com/lukasburg/django-search-admin-autocomplete
Should I make a pull request?
@lukasburg That makes sense, please create a PR.
Sorry, took some time. I have created a PR.
I have not edited the README or done anything else than the bare minimum to get it running. I free some time to do more edits, if you want me to :)
Great, thanks. I will take a look this week when I have time.