Question: I have the following model defined:

```
class PRegistration(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    create_date = models.DateTimeField(auto_now=False, auto_now_add=True)
    teamName = models.CharField(max_length=144)
    city = models.CharField(max_length=144)

```

How do I make all these fields read only in the admin page for all staff accounts except the superuser? I wanna do this without specifying the fields one by one so that I can reuse the code in multiple places.

Answer: 
If Your model.py contains

```
class PRegistration(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    create_date = models.DateTimeField(auto_now=False, auto_now_add=True)
    teamName = models.CharField(max_length=144)
    city = models.CharField(max_length=144)

```

If you want to make field **user, teamName** readonly for other staffs except superuser.
Add this code on your admin.py of same app.

```
@admin.register(PRegistration)
class PRegistrationAdmin(admin.ModelAdmin):
    list_display = ['user']
    search_fields = ['user']
    readonly_fields = ['user', 'teamName']

    def get_readonly_fields(self, request, obj=None):
        if request.user.is_superuser:
            return []
        return self.readonly_fields

```
You can override the `get_readonly_fields()` method of `AdminModel` class:

```py
from django.contrib import admin
from core import models

class UserAdmin(admin.ModelAdmin):
    def get_readonly_fields(self, request, obj=None):
        if request.user.is_superuser:
            return [] # list of read only fields name
        else:
            return ['your fields names'] # list of read only fields name

admin.site.register(models.User, UserAdmin)

```