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

CountryField shows up as "-" in admin when readonly #463

Open
dtcooper opened this issue Apr 10, 2024 · 1 comment
Open

CountryField shows up as "-" in admin when readonly #463

dtcooper opened this issue Apr 10, 2024 · 1 comment

Comments

@dtcooper
Copy link

dtcooper commented Apr 10, 2024

Hi there,

When a CountryField with multiple=True on a model has an associated ModelAdmin that is readonly for whatever reason (insufficient permissions or the field is marked in readonly_fields), it shows up in the admin UI as "-" no matter what.

Steps to reproduce:

  1. Create a model with a CountryField with multiple=True and associated readonly ModelAdmin,
# myapp/models.py
from django.db import models
from django_countries.fields import CountryField

class Test(models.Model):
    countries = CountryField(multiple=True)

# myapp/admin.py
from django.contrib import admin
from myapp.models import Test

class TestAdmin(admin.ModelAdmin):
    readonly_fields = ("countries",)

admin.site.register(Test, TestAdmin)
  1. Add multiple countries to the model
# In ./manage.py shell
from myapp.models import Test

test = Test(countries=["US", "CA"])
test.save()
  1. In Django's admin site observe something like this,
image

Note, what's expected is to see the list of countries render as readonly, perhaps as a comma-separated string?

@dtcooper
Copy link
Author

btw thanks for the great package! :)

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

No branches or pull requests

2 participants