1

I have created a model in one app and created a proxy model in another app. Now I want to give only view permission to a group of users for this proxy model in Django admin.

#core app
class Dress(models.Model):
    name = models.CharField("Nome", max_length=80)

#enza app
class EnzaDress(Dress):
    class Meta:
        proxy = True

In permission gird of Django user group record page, I did not see any entry to give view permission for this proxy model(EnzaDress) in Django admin.

My Django version is 1.11.5

Shahzad Farukh
  • 317
  • 1
  • 2
  • 17
  • 1
    Django provides only 3 permissions by default (add, change, delete). If you want 'view' permission, you have to add it manually. Look at answers here: https://stackoverflow.com/questions/27592658/how-to-move-models-in-other-section-in-django-admin-tool – jozo Oct 28 '17 at 14:00
  • Read also: https://stackoverflow.com/questions/15037642/django-proxy-model-permissions-do-not-appear – user2239318 Jan 27 '21 at 10:45

1 Answers1

1

You should manually create the permissions.

from django.contrib.auth.models import Permission, ContentType

content_type = ContentType.objects.get(app_label='enza', model='enzadress')

Permission.objects.get_or_create(codename='add_enzadress', name='Can add Enza Dress', content_type=content_type)
Permission.objects.get_or_create(codename='change_enzadress', name='Can change Enza Dress', content_type=content_type)
Permission.objects.get_or_create(codename='delete_enzadress', name='Can delete Enza Dress', content_type=content_type)

Hope this helps you!

Antony Orenge
  • 439
  • 5
  • 8