I want to display Customers from specific groups in the ListView, not able to understand how to get the queryset
class CustomerList(ListView):
model = Customer
queryset = Customer.objects.filter(member__groups__name__in=['online', 'whatsapp'])
template_name = 'customer/customer_list.html'
models.py
class Customer(models.Model):
member = models.ForeignKey(User, verbose_name=_("Customer"), on_delete=models.CASCADE)
contact = models.ForeignKey(Contact, verbose_name=_("Contact"), on_delete=models.CASCADE, blank=True, null=True)
...
Customers are added to the groups as below:
class AddUser(CreateView):
def post(self, request, *args, **kwargs):
form = UserForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
group, created = Group.objects.get_or_create(name='online')
user.groups.add(group)
user.save()