django-countries
django-countries copied to clipboard
CountryField shows up as "-" in admin when readonly
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:
- Create a model with a
CountryFieldwithmultiple=Trueand associated readonlyModelAdmin,
# 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)
- Add multiple countries to the model
# In ./manage.py shell
from myapp.models import Test
test = Test(countries=["US", "CA"])
test.save()
- In Django's admin site observe something like this,
Note, what's expected is to see the list of countries render as readonly, perhaps as a comma-separated string?
btw thanks for the great package! :)
Thanks! 😄
Just 2 years fix cycle 😂