Commit ad74ccdd authored by fred's avatar fred

bits of permission management

parent b3a63c86
......@@ -4,9 +4,19 @@ from django.contrib.auth.models import AbstractUser
from django.core import validators
from django.db import models
from emissions.models import Emission, NewsCategory
from emissions.models import Emission, Episode, NewsItem, NewsCategory
class User(AbstractUser):
emissions = models.ManyToManyField(Emission, null=True, blank=True)
news_categories = models.ManyToManyField(NewsCategory, null=True, blank=True)
def can_manage(self, object):
if self.is_staff:
return True
if isinstance(object, Emission):
return object in self.emissions.all()
if isinstance(object, Episode):
return object.emission in self.emissions.all()
if isinstance(object, NewsItem):
return object.emission in self.emissions.all()
return False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment