有没有办法可以采用模型,定义等效字段并使用它进行过滤?
示例模型:
class Manufacturer(models.Model):
uuid = UUIDField(primary_key=True)
company = models.ForeignKey(Company, db_column='company_uuid')
account_number = models.CharField(max_length=255, verbose_name=_('Account No'))
reference = models.CharField(max_length=255)
notes = models.TextField()
class Meta:
db_table = 'manufacturer'
然后我可以继续在模型上添加这样的东西吗:
self.field(name, self.company.name)
然后能够做到:
Manufacturer.objects.filter(name="Davies")