0

I have one parent model, called Farmer, which has foreign key relationship with two child models namely, FarmerAdvisory and ImageDetail. I want to show ImageDetail as an inline model to FarmerAdvisory in admin panel.

Is this possible?

FarmerAdvisory Models.py

class FarmerAdvisory(BaseModel):

STATUS_CHOICES = (
    ('OPEN', 'OPEN'),
    ('CLOSED', 'CLOSED')
)
id = models.AutoField(db_column='id', primary_key=True)
category = models.CharField(db_column='category', max_length=50, null=False, blank=False)
sub_category = models.CharField(db_column='sub_category', max_length=100, null=True, blank=True)
title = models.CharField(db_column='title', max_length=200, null=True, blank=True)
description = models.CharField(db_column='description', max_length=750, null=True, blank=True)
status = models.CharField(db_column='status', max_length=20, null=False, blank=False, default='OPEN',
                          choices=STATUS_CHOICES)
farmer_id = models.ForeignKey(Farmer, on_delete=models.CASCADE, null=True, db_column='farmer_id')
objects = models.Manager()

class Meta:
    managed = True
    db_table = 'farmer_advisory'

ImageDetails Models.py

class ImageDetail(BaseModel):
id = models.AutoField(db_column='id', primary_key=True)
filename = models.CharField(db_column='filename', max_length=100)
ref_type = models.CharField(db_column='ref_type', max_length=20, choices=ImageRefType)
ref_sub_type = models.CharField(db_column='ref_sub_type', max_length=100, blank=True, null=True)
ref_id = models.IntegerField(db_column='ref_id', blank=True, null=True)
farmer_id = models.ForeignKey('Farmer', models.DO_NOTHING, db_column='farmer_id', blank=True, null=True)
objects = models.Manager()

class Meta:
    managed = True
    db_table = 'image_detail'
  • yes it is possible you will get what you want from here https://levelup.gitconnected.com/django-admin-stacked-inline-example-many-to-many-relations-e81ae4b59f51 – Tanveer Ahmad Jan 11 '23 at 10:40

0 Answers0