Django Retrieve all Certifications based on names of the certificate -
i want retrieve prospects
have of certifications example, if certifications a, b & c, prospects have a, b & c should returned. if have more abc or less abc, should ignored.
in model.py
class certification(models.model): name = models.charfield(max_length=200, null=true, blank=true) def __str__(self): return "%s" % self.name class prospect(models.model): certification = models.manytomanyfield(certification, blank=true, related_name="certification_prospects")
how can write django query retrieve prospects have strictly certification of a, b & c?
from django.db.models import count certificates = certification.objects.count() prospect = prospect.objects.annotate(total=count('certification')).filter(total=certificates)
prospect var return object have certificates
Comments
Post a Comment