xadmin - 4

linkaiyi
Follow

xadmin fields readonly by change and editable by add

for inline class

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

for normal admin class

    def has_change_permission(self, request=None, obj=None):
        try:
            if self.org_obj:
                return False
            else:
                opts = self.opts
                codename = get_permission_codename('change', opts)
                return self.user.has_perm('%s.%s' % (opts.app_label, codename), obj)
        except AttributeError:
            return obj is None or None

set the field to readonly

    def get_readonly_fields(self):
        if self.org_obj:
            if self.org_obj.id:  # obj is not None, so this is an edit
                return ['company', ]  # Return a list or tuple of readonly fields' names
        else:  # This is an addition
            return []
Object has 0 attachments

Was this article helpful?

This article is viewed 14 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support