I am trying to filter a view related to the group to which the logged in user belongs to.
Lets say we have a user who belongs to a group DOGS. I figured out how to filter for a specific that means known group name = DOGS.
Models.py
from django.contrib.auth.models import Group
class Customer(models.Model):
customerName = models.CharField(max_length=50)
accountOwner = models.ForeignKey(Group, null=True, related_name='usGroup', on_delete=models.SET_NULL )
How do I do that in
views.py:
from django.contrib.auth.models import User, Group
@login_required
def home(request):
myData = Customer.objects.filter("Return only data of the group to which the user belongs".)
Do you have a hint? I only found solutions for filtering a specific groupname but not the property of the logged in user.
Thanks in advance!