I have those classes (simplified for sake of clarity):
class Entity(models.Model):
adresses = models.ManyToManyField(Address,
related_name='persons',
through='EntityAddress')
class EntityAddress(models.Model):
entity = models.ForeignKey(Entity, on_delete=models.CASCADE,
blank=False, null=False)
address_type = models.ForeignKey(AddressType, models.CASCADE,
blank=False, null=False)
address = models.ForeignKey(Address, on_delete=models.CASCADE,
blank=False, null=False)
class Address(models.Model):
summary = models.CharField(max_length=250, blank=True, null=True)
way = PolygonField(default=None, blank=True, null=True)
class Person(Entity):
user = models.OneToOneField(User, blank=False, null=False,
on_delete=models.CASCADE)
I want to have all Person
's whose addresses have a "not null" way
.
I do it like this:
for p in Person.objects.all():
for e_a in EntityAddress.objects.filter(entity=p,
address__way__isnull=False,):
# do whatever here:
pass
This is way too slow! Is there a way to make only one request?