Inlined hierarchy models in django admin site.

24 views
Skip to first unread message

Ayush Bisht

unread,
Jun 1, 2021, 2:06:24 AM6/1/21
to Django users
class Patient(models.Model):
     patient_id = models.CharField(max_length=60)


class PatientVaccineStatus(models.Model):
      patient = models.ForeignKey(Patient, related_name="patient_vaccine_status")

class Vaccine(models.Model)
     vaccine = models.ForeignKey(PatientVaccineStatus, related_name="vaccine_status")
 
..................................................................

Is there any way to merged all the tables in a single table of patient.

I successfully merge, PatientVaccineStatus table with Patient table, but Vaccine's table is not merging with the Patient. 

how can this hierarchy be merged in a single table.

DJANGO DEVELOPER

unread,
Jun 1, 2021, 4:31:43 AM6/1/21
to django...@googlegroups.com
class Vaccine(models.Model)
     vaccine = models.ForeignKey(PatientVaccineStatus, related_name="vaccine_status")
    patient = models.ForeignKey(Patient, related_name="patient")  # new line
apply this line and your patient model will be linked with Vaccine model 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com.

DJANGO DEVELOPER

unread,
Jun 1, 2021, 4:34:24 AM6/1/21
to django...@googlegroups.com
class Patient(models.Model):
     patient_id = models.CharField(max_length=60) # no need for adding patient id because django automatically creates ids
    patient_vaccine = models.ForeignKey(PatientVaccine, related_name="patient_vaccine")
   vaccine = models.ForeignKey(Vaccinet, related_name="vaccinet")

Ayush Bisht

unread,
Jun 2, 2021, 1:31:21 AM6/2/21
to Django users
yes, its true, but here it works as candidate key. so that we can identify the patient based in ICMR id's. 

DJANGO DEVELOPER

unread,
Jun 2, 2021, 1:36:36 AM6/2/21
to django...@googlegroups.com
btw have you applied in your models what I told you to do?

Ayush Bisht

unread,
Jun 2, 2021, 1:38:26 AM6/2/21
to Django users
thanks, .. it works for me.. but is there any other way to do these ??. as PatientVaccineStatus already connected to Patient model, and Vaccine connected to PatientVaccineStatus model.  Can't we merged all the tables of descendants to their parent model in this hierarchy fashion without linking each descendants to its.. super parent?? 

DJANGO DEVELOPER

unread,
Jun 2, 2021, 1:45:27 AM6/2/21
to django...@googlegroups.com
I think this the only way to lin different models with eachother. and I would like to hear more about linking the models with each other if there is anyone who can describe it to both of us.

Reply all
Reply to author
Forward
0 new messages