Read Only for specific rows Django not the empty filelds

Viewed 46

I am trying to create read only field for specific row where is values , and i wrote this script , with this script after saving the page i can not edit the empty rows ,in the page.

class Calender(admin.TabularInline):
    model = models.Calendar

    def get_readonly_fields(self, request, obj=None):
        if obj:
            return self.readonly_fields + ("registrations", "calendar")
        return self.readonly_fields
1 Answers

probably something like that?

def get_readonly_fields(self, request, obj=None):
    read_only = super().get_readonly_fields(request, obj)
    if obj and obj.registrations:
        read_only += ('registrations',)
    if obj and obj.calendar:
        read_only += ('calendar',)
    return read_only
Related