我有寵物的典範,它看起來像動態字段添加到Django模型
class Pet(models.Model):
STATUS_CHOICES=(
(1,'Listed for sale'),
(2,'Dead'),
(3,'Sold'),
)
name = models.CharField(_("name"), max_length=50)
species = models.ForeignKey(PetSpecies, related_name = "pets")
pet_category = models.ForeignKey(PetCategory, related_name = "pets")
pet_type = models.ForeignKey(PetType, related_name = "pets")
# want to add dynamic fields here depends on above select options(species, category, type)
color = models.CharField(_("color"), max_length=50, null=True, blank=True)
weight = models.CharField(_("weight"), max_length=50, null=True, blank=True)
我看了Dynamic Models,這將是對我有幫助嗎?還是我應該做點別的?如果有人知道請用一段代碼引導我。
謝謝:)
爲什麼重量是CharField? – 2011-04-18 07:32:40
我大致進入這些領域..要專注於動態領域... – Ahsan 2011-04-18 07:39:28
我很確定動態領域不是你在找什麼。你有任何你想添加的例子,取決於類別,物種,類型? – DTing 2011-04-18 07:51:45