Re: Making a field readonly according to the user in admin.py

2015-11-19 Thread 'Hugo Osvaldo Barrera' via Django users
On Wed, Nov 18, 2015, at 07:15, Victor wrote: > Dear experts, > > models.py > > class Book(models.Model): > title = models.CharField(max_length=100) > author = models.CharField(max_length=100) > quantity = models.IntegerField(db_column='quantitity',default=0) > class Meta: >

Re: Making a field readonly according to the user in admin.py

2015-11-18 Thread Mike Dewhirst
These three references should get you started. get_queryset[1] is useful for filtering the entire display based on the request user. readonly_fields[2] is a simple list of fields which are readonly for everyone. get_readonly_fields[3] is an Admin callable which can be overridden by your

Re: Making a field readonly according to the user in admin.py

2015-11-18 Thread Timothy W. Cook
While Jani's admonishments might be considered 'best practice' in some cases. Those do not always cover everyone's use case. I solved a similar issue allowing users with the superuser role to have edit access to some items that other staff do not have access to edit. Use the get_form method of

Re: Making a field readonly according to the user in admin.py

2015-11-18 Thread Jani Tiainen
Hi, In general you shouldn't be even trying to do this in admin since it's not designed for this kind of functionality. Admin is just a datacentric tool to view your data. It's never been meant to help implementing any businesslogic. And basically you only should let people in admin that

Making a field readonly according to the user in admin.py

2015-11-18 Thread Victor
Dear experts, models.py class Book(models.Model): title = models.CharField(max_length=100) author = models.CharField(max_length=100) quantity = models.IntegerField(db_column='quantitity',default=0) class Meta: db_table="book" admin.py class BookOption(admin.ModelAdmin):