0
當父屬性爲true時,我需要一個類(繼承),因此何時需要查找子類,將所有包含此屬性的屬性設置爲true。 之後,我將需要在管理面板中使用這個新類並作爲外鍵。例如:CustomerServices基於屬性值的Django模型繼承是可能的嗎?
看到代碼:
class Person(models.Model):
name = models.CharField(max_length=200)
active = models.BooleanField(default=True)
customer = models.BooleanField(default=False)
employee = models.BooleanField(default=False)
vendor = models.BooleanField(default=False)
def __str__(self):
return self.name
class People(Person):
registration_number = models.CharField(max_length=14)
birth_date = models.DateField()
sex = models.CharField(max_length=1)
class Company(Person):
registration_number = models.CharField(max_length=20)
foundation_date = models.DateField(blank=True, null=True)
class Meta:
ordering = ["name"]
class Customer(Person):
# I want to consider all Person object with customer=True
# I need this working and available in the Django Admin like others classes
class CustomerService(Customer):
service_name...
service_qtty...
service_price...
...
任何其他地方是的,這是可能的,但看起來像不好的設計決策。你想解決什麼樣的問題? – catavaran