I have a model that looks like this
# models.py
from django.db import models
class Level_0(models.Model):
Kode = models.CharField(max_length=10, null=False, blank=False, default="")
class Level_1(models.Model):
Kode = models.CharField(max_length=10, null=False, blank=False, default="")
Level_0= models.ForeignKey(Level_0, on_delete=models.CASCADE)
class Level_2(models.Model):
Kode = models.CharField(max_length=10, null=False, blank=False, default="")
Level_1 = models.ForeignKey(Level_1, on_delete=models.CASCADE)
# Level_0 = ????????????
# how do I create a connection to Level_0?
What I want to have is a field in Level_2
that automatically connects to Level_0
through Level_1
. How do I add that field in my Level_2
model?
It is already indirectly related to Level_0.
To access Level_0 corresponding you go through Level_1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.