On 11/08/2015 7:25 AM, Tony Peña wrote:
hi

i have this on my model.admin

class MyDomainAdmin(admin.ModelAdmin):
    list_display = ('domain', 'enabled', 'avscan', 'spamassassin',
'max_accounts')
    list_filter = ('enabled',)
    exclude = ('uid', 'gid', 'maildir')

# this part is my pseudo-code logic I want but i can't solved.
    if not user.is_superuser
        readonly_fields = ('max_accounts',)


There is a get_read_only() method in the admin.ModelAdmin class. It normally returns self.readonly_fields but you can give it a callable.

https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields

As well as defining any readonly fields (for everyone) you want something like ...

def ro_fields(self, request, obj=None):
    if obj is None or request.user.is_superuser:
        return self.readonly_fields
    else:
        return self.model._meta.get_all_field_names()

... then get_readonly_fields = ro_fields should make it happen like your pseudocode.

Mike



how can i set readonly for users staff? but normally modify for only
superusers?
--
Antonio Peña
Secure email with PGP 0x8B021001 available at https://pgp.mit.edu
<https://pgp.mit.edu/pks/lookup?search=0x8B021001&op=index&fingerprint=on&exact=on>
Fingerprint: 74E6 2974 B090 366D CE71Â  7BB2 6476 FA09 8B02 1001

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CALBaCdsUys33wv1n6tMaiKvEj%2BXcZRPytO_os9xNFW4ij0Vu0w%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CALBaCdsUys33wv1n6tMaiKvEj%2BXcZRPytO_os9xNFW4ij0Vu0w%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55C986EC.2030508%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to