I have models BottleType and OrganisationBottleType. And i want to annotate BottleType queryset by fields 'is_accepted' and 'points' from OrganisationBottleType.
OrganisationBottleType model:
class OrganisationBottleType(models.Model):
organisation = models.ForeignKey(
'Organisation',
related_name='organisation_bottle_types',
on_delete=models.CASCADE,
)
bottle_type = models.ForeignKey(
'machines.BottleType',
related_name='organisation_bottle_types',
on_delete=models.CASCADE,
)
is_accepted = models.BooleanField(...)
points = models.FloatField(...)
Suppose I have organisation_id and BottleType queryset, so for each object from queryset need to find OrganisationBottleType filtered by bottle_type and organisation and annotate fields 'is_accepted' and 'points'.
(When filtered OrganisationBottleType qs is found can just take first object from it, because it is assumed that the couple of fields: organisation - bottle_type is unique)
My idea is to use Subquery in annotation but i can't do it right.
I will be grateful for advice!