[英]Create separate models/tables that are subset of base model
I have a Transaction model that contains the list of all transactions from my bank account. 我有一个交易模型,其中包含银行帐户中所有交易的列表。 I want to create "sub" models that are just different categories of transactions.
我想创建只是不同类别的交易的“子”模型。 For instance, an Income model that just contains the deposits or a Bill model that contains the transactions that are from bills.
例如,仅包含存款的收入模型或包含来自票据的交易的票据模型。 The closest I could find were proxy models but either they are too complex for me to understand or I'm totally wrong anyway.
我能找到的最接近的是代理模型,但是它们要么太复杂以至于我无法理解,要么我完全错了。
class Transaction(models.Model):
date = models.DateField(default=datetime.date.today)
description = models.CharField(max_length=100)
category = models.CharField(max_length=100)
amount = models.DecimalField(max_digits=10, decimal_places=2)
def __str__(self):
return self.description + ' ' + str(self.amount)
class Income(Transaction):
class Meta:
proxy = True
Is this possible? 这可能吗?
您可以将category
字段与选择一起使用,而不是继承。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.