0

I am writing an application using Django 1.9, Guardian and Django Rest Framework.

I am trying to add a new perm (view_group) to groups. This new perm will control what groups logged-in user can see when calling the backend. I am using DjangoObjectPermissions.

Apparently it seems very daunting to add view_group permission to django.contrib.auth.models.Group class. I was wondering if anybody has managed to do it. If so please let me see the solution.

This my models

from django.contrib.auth.models import Group as realGroup
from django.db import models
from guardian import shortcuts
from users.models import User

if not hasattr(realGroup, 'parent'):
  field = models.ForeignKey(realGroup, blank=True, null=True, related_name='children')
  field.contribute_to_class(realGroup, 'parent')


class Group(realGroup):
  """
  This is a custom group.
  """

  class Meta:
    proxy = True
    permissions = (("view_group", "Can view group"), )

I am getting this exception Content Type matching query does not exist. Although I was trying to hack it and add to the system.

  • Hello, welcome to SO. Please do not leave the exception as an image on an external site. External links could become invalid anytime, and images can't be searched. To solve both problems, please edit your question and add the error message as text. Besides, for anything related to Django I would strongly recommend to add the Python tag. – Fabio says Reinstate Monica Jan 05 '16 at 23:43
  • Thank you! I will do it now. – Ahmad Abbad Jan 06 '16 at 14:40
  • I think you are getting very few views because of your tags. You haven't added Python, and for django you are using a "version" tag, that is, django-1.9. Is this question something specific to django-1.9, that would be different with a previous version? If not, I suggest changing that tag to the standard "django". The reason is that most people follow general tags, but not specialised ones. django-1.9 has 2 followers (you can see it if you hover over it), django has 17000. Change it, or add it, and you should get a lot more visibility. Other than this, good luck! – Fabio says Reinstate Monica Jan 07 '16 at 18:14
  • Good point will do that now thank you again! – Ahmad Abbad Jan 07 '16 at 22:38

0 Answers0