Reputation: 1091
Unfortunately, I'm still using django 1.4 and the verbose_name doesn't work for foreign keys. It is there a way to change the label of a foreign key. For now, it is not working:
class ProductVariant(models.Model):
product = models.ForeignKey(TestProduct, verbose_name='test product', on_delete=models.PROTECT)
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
I hope you can help me.
Thanks in advance!
Upvotes: 0
Views: 392
Reputation: 13731
verbose_name
should work with Django 1.4 according to the 1.4 docs.
I think because you're overriding the field in the form it's not using the verbose name for the label. What you could do is set the label on the 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
I'm not quite sure how to use the model's verbose name on the field though, so you might have to define it twice.
Upvotes: 1