我有这样的旧数据库:
class CarParamType(models.Model):
name = models.CharField(max_length=50)
unit = models.CharField(max_length=10)
class CarParam(models.Model):
car = models.ForeignKey(Car)
car_param_type = models.ForeignKey('CarParamType')
value = models.CharField(max_length=20)
class DriveType(models.Model):
name = models.CharField(max_length=20)
class Car(models.Model):
vin = models.CharField(max_length=20)
以及此类管理站点:
class CarParamAdmin(admin.TabularInline):
model = CarParam
@admin.register(Car)
class CarAdmin(CustomModelAdmin):
inlines = [
CarParamAdmin,
]
CarParamType填充了诸如重量,宽度,颜色之类的名称,最重要的是在CarParam值字段中存在与DriveType id相关的“行车”记录。
可能会得到类似的东西:
if car_param_type.name == 'drive':
form = forms.ModelChoiceField(queryset=DriveType.objects.all())
.. in我的TabularInline内部吗?