Many to Many Filter only object Output? #1422
Unanswered
Bastilla123
asked this question in
Q&A
Replies: 1 comment
-
Implement |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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")
widget=forms.CheckboxSelectMultiple, label="Produktinteresse")
views.py:
def search(request):
liste = Address.objects.all()
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?
Beta Was this translation helpful? Give feedback.
All reactions