I have 2 models
class Service(models.Model):
name = models.CharField(max_length=100)
class ServiceType(models.Model):
name = models.CharField(max_length=100)
services = models.ManyToManyField(Service, related_name='service_types')
Now i have a list of services and want to get ServiceType with only this services. If not exists, create it.
I don't understand how to build this queryset threw Django ORM.....
queryset like
ServiceType.objects.filter(services__id__in=services.values_list('id', flat=True)).annotate(count=Count('services')).filter(count=services.count())
returns all ServiceTypes with needed services and not needed services...
P.S. Sorry for my English