0๐
โ
Try this
qs = Society.objects.all()
citys = City.objects.values_list('name', flat=True)
data = []
for name in citys:
response = qs.filter(name__iendswith=name)
if response.exists():
data.append(response)
print(data)
Or You can do something like this (i will recommend this)
import operator
from django.db.models import Q
from functools import reduce
qs = Society.objects.all()
citys = City.objects.values_list('name', flat=True)
clauses = (Q(name__iendswith=name) for name in citys)
query = reduce(operator.or_, clauses)
data = qs.filter(query)
1๐
you can try something like this
qs = Society.objects.all()
citys = City.objects.all().values_list('name', flat=True)
qs = qs.filter(name__endswith=list(citys))
๐คrahul.m
- [Answered ]-SMTPSenderRefused at /submit_contact_form/ โ 5.5.1 Authentication Required
- [Answered ]-Django template find dictionary in list
- [Answered ]-Context Variable will not show up in Django template
- [Answered ]-Pickup "unique item" of a field in a django model using python
- [Answered ]-Django: performing a SQL match all in Django
Source:stackexchange.com