djongo icon indicating copy to clipboard operation
djongo copied to clipboard

How to make a field in ArrayModelField readonly in Django admin page?

Open hchings opened this issue 5 years ago • 3 comments

The document didn't specify how to make the fields in abstract model readonly in Django's admin.

Python script

For example, I have two models as shown below:

class MyNestedModel(models.Model):
        class Meta:
                abstract = True
    
        field_2 = models.CharField(max_length=20, default='', blank=True)

class MyModel(models.Model):
        field_1 = models.ArrayModelField(
                model_container=MyNestedModel,
                model_form_class=MyNestedForm,
                default=[]
        )

How could I make field_2 readonly in Django's admin page? For fields in MyModel, we can just do the settings in admin.py:

class MyModelAdmin(admin.ModelAdmin):
    readonly_fields = ['...']

Is there any similar way for the abstract model?

Thank you.

hchings avatar Aug 02 '19 02:08 hchings

+1

amirasaran avatar Dec 30 '19 10:12 amirasaran

I also need this feature

Webblitchy avatar Feb 24 '20 10:02 Webblitchy

+1

xift810 avatar Jun 13 '21 01:06 xift810