Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verbose name neglect by formfield_for_foreignkey . #45

Open
ritiksoni00 opened this issue Aug 28, 2022 · 0 comments
Open

verbose name neglect by formfield_for_foreignkey . #45

ritiksoni00 opened this issue Aug 28, 2022 · 0 comments

Comments

@ritiksoni00
Copy link

if we had given a verbose name for the model field and if we try to customize our FK representation in the admin panel then we will use formfield_for_foreignkey as shown in the block below

def formfield_for_foreignkey(self, db_field, request, **kwargs):
    if db_field.name == 'category':
        return CategoryChoiceField(queryset=Category.objects.all())
    return super().formfield_for_foreignkey(db_field, request, **kwargs)

and here it will neglect the given verbose name (tbh IDK why its happening maybe DB layer is overridden by the form layer!)
so we have to provide the label argument again

def formfield_for_foreignkey(self, db_field, request, **kwargs):
    if db_field.name == 'category':
        return CategoryChoiceField(queryset=Category.objects.all(), label='_XYZ_')
    return super().formfield_for_foreignkey(db_field, request, **kwargs)

link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant