Soliman
Soliman

Reputation: 371

How to show the number in ManyToManyField appear as number but not ediatbale

How I can show the number of models.ManyToManyField as a number but not editable because when I set editable=False I couldn't see the number of users in the Django model

like this

    viewers = models.ManyToManyField(Account, editable=False)

Upvotes: 1

Views: 34

Answers (1)

Pradip Kachhadiya
Pradip Kachhadiya

Reputation: 2235

Use readonly_fields in admin.py

admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    ....
    readonly_fields = ['id','viewers']  

Upvotes: 2

Related Questions