-
Notifications
You must be signed in to change notification settings - Fork 47
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
Django2 now supports AutoComplete via select2, can django-admin-list-filter-dropdown? #7
Comments
Excellent, many thanks for the suggestion! I was thinking about this, but didn't look into the implementation yet. I'll take a look at your pull request in near future. |
Any news about this feature? It will be implemented? Thanks |
@rocchidavide see discussions and code at pull request #8, at the moment it is incomplete and it seems @macolo does not currently have time to finish the implementation. Feel free to help out :)! |
You can add a custom js file, say file name is (function ($) {
console.debug($, 'LOADED');
$(function () {
$('select[auto-select=1]').select2();
});
}(django.jQuery)); Then, define a custom widget like: class AutoSelectWidget(Select):
@property
def media(self):
extra = "" if settings.DEBUG else ".min"
return Media(
js=[
f"admin/js/vendor/jquery/jquery{extra}.js",
f"admin/js/vendor/select2/select2.full{extra}.js",
"admin/js/jquery.init.js",
"js/autoselect.js",
]
) Finally, use it in a form: class SomeForm(ModelForm):
class Meta:
model = SomeModel
fields = "__all__"
widgets = {
"field": AutoSelectWidget(attrs={"auto-select": 1})
} And get rid of this library to use pure django. |
@kigawas How do you envision integrating your solution to Django admin That is, what would you write instead of class EntityAdmin(admin.ModelAdmin):
...
list_filter = ( ??? ) Note that the solution proposed by @macolo here uses AJAX to fetch select results from the backend - do you have a suggestion how to implement this? |
FYI: |
@kigawas Cool, thanks for the links! Would you consider submitting a pull request to add autocomplete functionality? Note that this project is MIT-licensed though, similar to the liberal BSD license of Django itself. |
Anybody working on this? |
Not at the moment, sorry. Getting it right seems not to be trivial unfortunately. Let's hope a brave champion arises 👩🚒, if not then eventually I hope to get time for this. |
To answer this question: class EntityAdmin(admin.ModelAdmin):
...
list_filter = ( ??? ) This is what I would want: class EntityAdmin(admin.ModelAdmin):
list_filter = (("field", AutocompleteFilter),) (i.e. similar to how one uses SimpleRelatedFilter from django) I haven’t looked yet in how to achieve that; in a previous project with lots of custom filter, I stopped at the simpler form |
As this is large work and I don't currently have time for this, perhaps we could set up a bounty at Issuehunt (or some other bounty site)? Please comment if you support that and how much you would be willing to contribute - or if you would like to pick up the bounty. I'm willing to contribute $20 myself. |
FWIW, I have used https://github.com/farhan0581/django-admin-autocomplete-filter in my project and it works pretty well. Thanks nonetheless for writing this one and making it available! I haven’t looked recently if this package provides features that that other doesn’t, in which case maybe joining forces could be an idea? |
Jup that's true, I actually am also using that solution :) |
Many thanks for the link @merwok (and thanks to @kigawas once more for suggesting it previously) and cheers for your great work @farhan0581! Would be awesome to collaborate, but Farhan's work is licensed under GPL 3, so I cannot even look at the code for the time being if I want to keep the more liberal MIT license. @farhan0581, what do you think about joining forces? I'm more than happy to merge your code and hand over maintenance. |
Yeah sure man ! ,BTW thanks for your great work. |
Great :)! I propose the following action plan then:
Does this sound good? Is it OK for you to redirect I'll wait for your confirmation before proceeding. |
@farhan0581, did you have time to think about the plan that I proposed in April? Please feel free to suggest amendments to the plan or decline freely, then I can explore other avenues forward. |
@farhan0581 @mrts, Any news about the merge ? |
@qcoumes, still waiting for @farhan0581's answer on the proposal. |
Taking a look at @farhan0581's github activity, I wouldn't expect an answer from him. |
I cannot unfortunately merge GPL 3-licensed code, so his opinion is needed - @farhan0581, any news from your side? |
@merwok @macolo you mention that you use https://github.com/farhan0581/django-admin-autocomplete-filter. Do you use it in closed-source commercial projects? If yes, then how do you comply with the GPL 3 license? As far as I can understand, using GPL 3 licensed code means that you have to publish the source code of your project as well? |
As long as your project doesn't release software for your users to install, GPL isn't a problem, to my understanding. If you wanted to protect a library from use in a closed source Service, for example, you would want to use the AGPL, not the GPL. |
Alright, all good then, thanks for explaining! I have to admit that I haven’t investigated licensing implications thoroughly enough. |
@mrts I'd be up for a chat or call sometime on the subject if you'd find that useful. |
I see that https://github.com/shamanu4/dal_admin_filters is MIT-licensed, this could be used for inspiration instead of https://github.com/farhan0581/django-admin-autocomplete-filter. |
+1 |
The Autocomplete URL can be retrieved via a template tag:
The problem is to insert
admin/js/vendor/select2/select2.full.js
afteradmin/js/vendor/jquery/jquery.js
but before/static/admin/js/jquery.init.js
which enablesnoConflict
for jQuery and hidesjQuery
from the global scope (which select2 needs). The filter's__init__
getsModelAdmin
instance passed, however itsMedia
instance cannot be changed at this point. The only option I found is extending the admin'schange_list.html
template, which adds complexity to the module (needs to be inserted beforedjango.contrib.admin
inINSTALLED_APPS
.It works, but its far from being modular.
The text was updated successfully, but these errors were encountered: