Hi, The following PR is ready to merge and implements this: https://github.com/django/django/pull/6734
I will squash the commits as soon as I'm back in the office (next week) and it will probably be merged soon. Bests Olivier On 25 Oct 2016 19:03, "Luis Zárate" <[email protected]> wrote: > you are looking something like > https://code.djangoproject.com/ticket/7150 > https://code.djangoproject.com/attachment/ticket/7150/ > admin_view-permission-1.0.patch > https://code.djangoproject.com/attachment/ticket/7150/newforms-admin-view- > permission-r7737.patch > https://code.djangoproject.com/ticket/8936 > https://code.djangoproject.com/ticket/22452 > https://code.djangoproject.com/ticket/18814 > https://code.djangoproject.com/ticket/17295 > https://code.djangoproject.com/ticket/3984 > https://code.djangoproject.com/ticket/2058 > https://code.djangoproject.com/ticket/820 > > > I don't know why Django doesn't support readonly view, various proposal > was summit and always was reject. > > Django Admin needs Readonly View functionality for a complete > implementation of CRUD. > > There is a lot of scenarios where you need readonly view for your staff. > And yes you can implement a readonly in django admin without modify django > core admin with some tricks. > > I > > > > 2016-10-24 7:26 GMT-06:00 Derek <[email protected]>: > >> Would it be possible to add these extra admin methods into a parent >> class; and then have all your individual model admins inherit from it? >> Ditto for the models.py >> >> On Sunday, 8 February 2015 21:15:42 UTC+2, Hangloser Firestarter wrote: >>> >>> Solved. >>> >>> In __init__.py >>> ... >>> from django.db.models.signals import post_syncdb >>> from django.contrib.contenttypes.models import ContentType >>> from django.contrib.auth.models import Permission >>> >>> def add_view_permissions(sender, **kwargs): >>> """ >>> This syncdb hooks takes care of adding a view permission too all our >>> content types. >>> """ >>> # for each of our content types >>> for content_type in ContentType.objects.all(): >>> # build our permission slug >>> codename = "view_%s" % content_type.model >>> >>> # if it doesn't exist.. >>> if not Permission.objects.filter(content_type=content_type, >>> codename=codename): >>> # add it >>> Permission.objects.create(content_type=content_type, >>> codename=codename, >>> name="Can view %s" % >>> content_type.name) >>> print("Added view permission for %s" % content_type.name) >>> >>> # check for all our view permissions after a syncdb >>> post_syncdb.connect(add_view_permissions) >>> ... >>> >>> In admin.py >>> ... >>> class MyAdmin(admin.ModelAdmin): >>> def has_change_permission(self, request, obj=None): >>> ct = ContentType.objects.get_for_model(self.model) >>> salida = False >>> if request.user.is_superuser: >>> salida = True >>> else: >>> if request.user.has_perm('%s.view_%s' % (ct.app_label, >>> ct.model)): >>> salida = True >>> else: >>> if request.user.has_perm('%s.change_%s' % >>> (ct.app_label, ct.model)): >>> salida = True >>> else: >>> salida = False >>> return salida >>> >>> def get_readonly_fields(self, request, obj=None): >>> ct = ContentType.objects.get_for_model(self.model) >>> if not request.user.is_superuser and >>> request.user.has_perm('%s.view_%s' % (ct.app_label, ct.model)): >>> return [el.name for el in self.model._meta.fields] >>> return self.readonly_fields >>> ... >>> >>> in models.py >>> ... >>> class City(models.Model): >>> nome_cidade = models.CharField(max_length=100) >>> estado_cidade = models.CharField(max_length=100) >>> pais_cidade = models.CharField(max_length=100) >>> >>> def __str__(self): >>> return self.nome_cidade >>> >>> class Meta: >>> permissions = ( >>> ('view_city', 'Can view city'), >>> ) >>> ... >>> >>> Thank's for help! >>> >> -- >> 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 https://groups.google.com/group/django-users. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/django-users/74f952fe-f0f5-4fb3-abd4-d6736cbd2743%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/74f952fe-f0f5-4fb3-abd4-d6736cbd2743%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > "La utopía sirve para caminar" Fernando Birri > > > -- > 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 https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/CAG%2B5VyMVxD7n3FoJf%3D8xgweBAXueK6qv5tUAQhe_Dg8A% > 2B6ZLLQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAG%2B5VyMVxD7n3FoJf%3D8xgweBAXueK6qv5tUAQhe_Dg8A%2B6ZLLQ%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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAExk7p3TrNVek7jD0KL2Zx_x8sAi6azW5WKXtqbgsk8hhKoWFA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

