0
我的車型領域看起來像以下:Django中使用來自兩個不同車型在另一個模型
class City(models.Model):
name = models.CharField(max_length=20, blank=False)
pin = models.IntegerField(null=False,)
def __str__(self):
return u"%s" % (self.name)
class Localities(models.Model):
name = models.CharField(max_length=50, blank=False,)
city = models.ForeignKey(City, on_delete=models.CASCADE)
def __str__(self):
return u"%s, %s" % (self.name, self.city)
class Hall(models.Model):
name = models.CharField(max_length=30, blank=False, verbose_name="Name of the Marriage Hall",)
city = models.ForeignKey(City, on_delete=models.CASCADE,)
landmarks = models.CharField(max_length=50, blank=False, verbose_name="Landmarks of the Marriage Hall",)
seating_capacity = models.IntegerField(null=False, verbose_name="Seating capacity of the Marriage Hall",)
ac = models.BooleanField(null=False, verbose_name="Is the Marriage Hall AC?",)
garden_lounge = models.BooleanField(null=False, verbose_name="Is the Marriage Hall garden_lounge?",)
avg_user_rating = models.DecimalField(max_digits=10, null=False, decimal_places=5, verbose_name="Average user rating of the Marriage Hall",)
comments = models.CharField(max_length=50, blank=False, verbose_name="Customer comments for this Marriage Hall",)
rent = models.DecimalField(max_digits=10, decimal_places=5, blank=True,)
def __str__(self):
return u"%s, %s" % (self.name, self.city)
我想有也是在地方我的大廳模型,但是當我選擇一個特定的城市時,與這個城市相關的地區應該被填充。
我該如何做到這一點?我如何修改我的模型?
爲什麼你需要在編輯大廳頁面的地方?他們不是(直接)相關的 – e4c5
嗯,我希望他們有某種相關性。邏輯如下:我選擇一個城市,然後選擇我的大廳所在的城市。 – Nitish