I have three model Pesticide, Disease and Instruction what i want is to get all disease with relation to pesticide which relate to instruction model
class Disease(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Pesticide(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Treatment(models.Model):
disease = models.ForeignKey(Disease, related_name='treatments', on_delete=models.DO_NOTHING)
pesticide = models.ForeignKey(Pesticide, related_name='treatments', on_delete=models.DO_NOTHING)
def __str__(self):
return self.instruction
and serializer
class PesticideSerializer(serializers.ModelSerializer):
class Meta:
model = Pesticide
fields = ('id', 'name')
class DiseaseSerializer(serializers.ModelSerializer):
pesticides = PesticideSerializer(source='treatment_set', read_only=True)
class Meta:
model = Disease
fields = [
'id',
'name',
'pesticides',
]
My problem is that i can not get pesticides in django serializer