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

Prefer field_path for admin filter to follow relations #432

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SebCorbin
Copy link

When filtering on a CountryField from a relation, the admin will break with a FieldError: Cannot resolve keyword 'country' into field. Choices are: ...

Full example code:

# models.py
class Contact(models.Model):
    country = CountryField(
        verbose_name=_("Country"),
        blank=True,
        null=True,
    )


class Payment(models.Model):
    contact = models.ForeignKey(
        "myapp.Contact", verbose_name=_("Contact"), on_delete=models.RESTRICT
    )
# admin.py
class PaymentAdmin(ModelAdmin):
    model = Payment
    list_filter = [
        ("contact__country", CountryFilter),
    ]

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

Successfully merging this pull request may close these issues.

2 participants