我尝试在管理员中订购属性,但它不起作用
模型
class Physic(models.Model):
name = models.ForeignKey(Property, verbose_name=_('name'), null=True, blank=True,)
lapropriete = models.CharField(_('property'), max_length=100)....
class Essai_Temperature(models.Model):
name = models.ForeignKey(Material,
nature_unit = models.ForeignKey(Property,
choix = ChainedForeignKey(Physic, verbose_name=_('properties'), null....
形式
class Essai_TemperatureForm(forms.ModelForm):
class Meta:
model = Essai_Temperature
def __init__(self, *args, **kwargs):
super(Essai_TemperatureForm, self).__init__(*args, **kwargs)
self.fields['choix'].queryset = Physic.objects.order_by('-lapropriete')
管理员
class Essai_TemperatureInline(admin.TabularInline):
model = Essai_Temperature
form = Essai_TemperatureForm
extra = 5
这里有什么问题?
也许是choix?
我有下拉列表('硬度维氏(GPa)',剪切模量(MPa)'......
答案 0 :(得分:0)
为什么不使用ModelAdmin
的{{3}}(这也适用于TabularInline
- ordering
attribute)
class Essai_TemperatureInline(admin.TabularInline):
model = Essai_Temperature
form = Essai_TemperatureForm
ordering = ('-choix__lapropriete',)
extra = 5