I wrote this code to make read only field, but i want to make an exception that if there is value then that row will only readonly , and if there is not any value the it will be editable,
model.py
class Name(models.Model):
name = models.BooleanField(default=False)
id = models.BooleanField(default=False)
def __str__(self):
return f"{self.name}"
admin.py
class Name(admin.ModelAdmin):
model = models.Name
def get_readonly_fields(self, request, obj=None):
if obj:
return self.readonly_fields + ("name", "id")
return self.readonly_fields


