yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.79k stars 466 forks source link

The selected filter does not filter the model in the admin panel #1353

Open SiberMix opened 5 months ago

SiberMix commented 5 months ago

The selected filter does not filter the model in the admin panel

I migrated DAL==3.5.1 for django 4 (replace ugettext to gettext) I did this because the dropdown with the autocomplete did not work and there was ---- Now I select an entry from the dropdown, but the model in the admin panel is not filtered - what could be the matter?

class OfferFilter(AutocompleteFilter):
    title = _('Оффер')
    field_name = 'name'
    autocomplete_url = 'admin:offer-search-select'

    def get_queryset_for_field(self, model, name):
        return Offer.objects.all()

    def queryset(self, request, queryset):
        if self.value() and self.value().isdigit():
            return queryset.filter(id=int(self.value()))
        return queryset
@admin.register(Offer)
class OfferAdmin(ExportMixinAdmin, ArchiveMixin, TabbedTranslationAdmin, NestedModelAdmin, AdminConfirmMixin):
    inlines = [OfferSourceTypeNoteInline, OfferPageInline, OfferTargetInline, OfferContestConfigInline]
    filter_horizontal = ['countries', 'custom_webmasters', 'offer_source_types']
    list_display = (
        'id', 'name', 'advertiser_link', 'offer_manager', 'publish_dt', 'offer_type', 'is_hidden', 'status',
        'last_start', 'stat_refresh_info', 'integration_method', 'is_sponsor_display', 'get_sponsor_position'
    )
    search_fields = ['name', 'search_options', '=id']

    list_filter = (
        OfferFilter, )

Please help me.

I am migrating a very large project from django version 1.9 to >4

I want to cry