Hello,

i have installed per pip django-filters. 

Models.py:

class Productinterests(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255, default="", blank=False, null=
False)

class Address(models.Model):
   productinterests = models.ManyToManyField(Productinterests,blank=True, 
default=0)
   lastname = models.CharField(max_length=255, default="", )
   firstname = models.CharField(max_length=255, default="", blank=True, null
=True)

filters.py:
   class AddressFilter(django_filters.FilterSet):
lastname = django_filters.CharFilter(lookup_expr='icontains',label=
"Nachname")
firstname = django_filters.CharFilter(lookup_expr='icontains', label=
"Vorname")

    productinterests = django_filters.ModelMultipleChoiceFilter(
to_field_name='name',queryset=Productinterests.objects.all(),
widget=forms.CheckboxSelectMultiple, label="Produktinteresse")

    class Meta:
       model = Address
       fields = ['lastname','firstname','productinterests' ]

views.py:
   def search(request):
         liste = Address.objects.all()

         address = AddressFilter(request.GET, queryset=liste)
return render(request, 'search/address_list.html', {'filter': user_filter})


*Problem: Website shows in Multiselect Productinterest only as Output:*
* "Productinterests object (1)" instead of name from object. How can i 
output name?*

Regards              

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/636ab5c4-d24e-42ab-bec2-be2eab833bdbn%40googlegroups.com.

Reply via email to