我有一个有外国血统的django模型。我想用这个模型的另一个字段的内容来限制它的选择。在
此代码起作用:
class PhysicalProperty(models.Model):
property_quantity = models.ForeignKey(Quantity)
default_unit = models.ForeignKey(MeasurementUnits, limit_choices_to = {'quantity': 1 )
但是它从测量中得到了所有的记录测量数量=1。我需要将查询设置为测量数量= PhysicalProperty.property_数量. 在
这个代码行不通
^{pr2}$
你不能在课堂上使用self。self表示类的实例。在
你可以使用init方法
这样,每次你做
physical_property = PhysicalProperty()
,physical_property.default_unit
将与同一对象的属性数量相同。在相关问题 更多 >
编程相关推荐