2014-02-19 140 views
0

不幸的是,我仍在使用django 1.4,verbose_name不適用於外鍵。 有沒有辦法改變外鍵的標籤。現在,它不工作:Django:在管理中更改字段標籤不起作用

class ProductVariant(models.Model): 
    product = models.ForeignKey(TestProduct, verbose_name='test product', on_delete=models.PROTECT) 

ProductVariant

class ProductVariantForm(forms.ModelForm): 
    product = forms.ModelChoiceField(queryset=TestProduct.objects.order_by("product__article_code")) 
    test_software = forms.ModelChoiceField(queryset=TestSoftware.objects.order_by("name"))  
    class Meta: 
     model = ProductVariant 

class ProductVariantAdmin(admin.ModelAdmin): 
    fields=["product", "test_software", "test_variables", "name", "description"] 
    list_display = ("name", "product_name", "test_software_name", "test_variables", "description") 
    search_fields = ["name"] 
    form = ProductVariantForm 

我希望你能幫助我。

提前致謝!

+0

嘗試:'product = models.ForeignKey(TestProduct,verbose_name = u'test product',on_delete = models.PROTECT)'如果它有效,我會發布我的答案。 – Silwest

+0

@Silwestpl它沒有工作:'( – Ruben

回答

1

verbose_name應根據1.4 docs與Django 1.4一起使用。

我認爲,因爲您在覆蓋字段的形式中沒有使用標籤的詳細名稱。你可以做的是在ModelChoiceField上設置標籤。

class ProductVariantForm(forms.ModelForm): 
    product = forms.ModelChoiceField(label="Test Product", queryset=TestProduct.objects.order_by("product__article_code")) 
    test_software = forms.ModelChoiceField(queryset=TestSoftware.objects.order_by("name"))  
    class Meta: 
     model = ProductVariant 

我不太知道如何在球場上使用模型的詳細名稱,因此,您可能需要定義它的兩倍。

+0

謝謝。它像一個魅力。 – Ruben

相關問題