Wednesday, October 9, 2013

Re: admin.py: putting "if condition" in ModelAdmin according to username

In Admin Site, you can manage users permissions for Add, Delete, Modify of every model on your site.


2013/10/9 Vittorio <ml-vic@de-martino.it>
For the sake of simplicity let's suppose I have

models.py

class Book(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publisher = models.ForeignKey(Publisher)

Under admin I would like that some username (say "vic" and  "lucky") can edit every field of the change form while other users ("tom","sue") can only visualize the same data without modification.  I think to put some "if condition" in admin.py of this kind


class BookOption(admin.ModelAdmin):
   if username  in ["tom", "sue"]:
                readonly_fields = ['title','authors','publisher']
    fields=(('title'),('authors', 'publisher'))..
    .....
   admin.site.register(Book,BookOption)


How can I do it?

Ciao
Vittorio

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/F0A087D2-8E11-4B0B-8D95-6FC131854994%40de-martino.it.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rafael E. Ferrero

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAJJc_8U3EbZXHVSucFndA25V%3DuYyen%3DGgUsyHmzLncD5DuGi2w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment