Newbie here, I have two models which are below
class ReceipeMaster(models.Model):
receipe_type = models.CharField(max_length=50, choices=TYPE_OPTIONS, default=TYPE_OPTIONS[0])
item = models.ForeignKey(Item, on_delete=models.CASCADE, related_name='receipe')
units = models.IntegerField(default=1)
status = models.BooleanField(default=True)
class ReceipeDetail(models.Model):
master = models.ForeignKey(ReceipeMaster, on_delete=models.CASCADE, related_name='items')
item_type = models.ForeignKey(Item_type, null=True, on_delete=models.PROTECT)
item = models.ForeignKey(Item, on_delete=models.PROTECT)
quantity = models.IntegerField()
I have a detailed view DetailView
class ReceipeDetailView(PermissionRequiredMixin, DetailView):
permission_required = 'item_management.view_receipemaster'
model = ReceipeMaster
template_name = 'receipes/show.html'
context_object_name = 'receipe'
I would like to prefetch_related
or select_related
on the ReceipeMaster
model and as well as the ReceipeDetail
model. Simply prefetch on both models.
Regards