Please somebody can teachme how create identifying and non identifying relationship in Django, similar the image for reference. Thank you.
Image for reference.
Please somebody can teachme how create identifying and non identifying relationship in Django, similar the image for reference. Thank you.
Image for reference.
I guess ForeignKey
is what you are looking for as "identifying relationship". Then
# models.py
from django.db import models
class District(models.Model):
# django will automatically create id field
# nombre = models.SOMEFIELD()
pass
class Headquarter(models.Model):
district = models.ForeignKey(District, on_delete=models.CASCADE)
# nombre = models.SOMEFIELD()
# activo = models.SOMEFIELD()
class Building(models.Model):
# This "district" field looks pointless, as we can simply
# follow relation like a_building.headquarter.district
district = models.ForeignKey(District, on_delete=models.CASCADE)
headquarter = models.ForeignKey(Headquarter, on_delete=models.CASCADE)
# nombre = models.SOMEFIELD()
I believe the pattern is obvious enough for you, and I leave Department
to your own.
I have no idea what you mean by "non identifying relationship". You might want to give implementation details, so that I can be of more help.
PS: Django is well documented. You can find most Django features there.
PS 2: Please follow @Frankline and re-write your question. Welcome to Stack Overflow.