django-countries icon indicating copy to clipboard operation
django-countries copied to clipboard

CountryField shows up as "-" in admin when readonly

Open dtcooper opened this issue 1 year ago • 1 comments

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 avatar Apr 10 '24 15:04 dtcooper

btw thanks for the great package! :)

dtcooper avatar Apr 12 '24 15:04 dtcooper

Thanks! 😄

dtcooper avatar Nov 04 '25 14:11 dtcooper

Just 2 years fix cycle 😂

SmileyChris avatar Nov 05 '25 10:11 SmileyChris