Django admin: make field editable in add but not edit

Do not set self.readonly_fields to avoid thread issues. Instead override get_readonly_fields method:

def get_readonly_fields(self, request, obj=None):
    if obj: # obj is not None, so this is an edit
        return ['third_party_id',] # Return a list or tuple of readonly fields' names
    else: # This is an addition
        return []

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)