I'm starting to use Django, but I'm just a beginner. I have a problem with Django Queries, and although I've done a lot of research online, I haven't found any answers that can help me.
Models.py:
class Articles(models.Model):
ID = models.AutoField(primary_key=True)
description = models.TextField()
price = MoneyField(blank=True, null=True, decimal_places=2, max_digits=8, default_currency='EUR')
class Meta:
ordering = ('description',)
def __str__(self):
return self.description
class Interventions(models.Model):
ID = models.AutoField(primary_key=True)
start_date = models.DateField()
description = models.TextField()
Articles_ID = models.ManyToManyField(Articles, through="Detail", blank=True)
class Detail(models.Model):
ID = models.AutoField(primary_key=True)
article_id = models.ForeignKey(articles, on_delete = models.CASCADE)
Intervention_ID = models.ForeignKey(Interventions, on_delete = models.CASCADE)
quantity = models.IntegerField(null=True, blank=True, default='1')
I would like to be able to create a Query that takes all the records of the 'Interventions' model and all the records of the 'Details' table.
The problem is that if an intervention is made, but without having used any article, the intervention itself is not displayed.
How can I do? I tried with prefetch_related but it doesn't seem to work. Heartfelt thanks to everyone.