site_tps/content/models.py

54 lines
1.3 KiB
Python
Raw Normal View History

2018-01-14 12:19:11 +00:00
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import Group
2018-02-28 14:06:55 +00:00
from django.conf import settings
2018-01-14 12:19:11 +00:00
2018-02-28 20:25:44 +00:00
from users.models import SchoolProfile
class Category(models.Model):
"""Une catégorie de contenu."""
name = models.CharField(
max_length=255,
2018-01-24 10:44:54 +00:00
verbose_name="Nom de la catégorie"
)
2018-02-28 14:06:55 +00:00
description = models.TextField(
verbose_name="Descriton de la catégorie",
default=""
)
image = models.ImageField(
verbose_name="Illustration de la catégorie",
null=True,
)
def get_absolute_url(self):
2018-01-30 22:07:08 +00:00
return reverse('content:category-list', kwargs={'pk':self.pk})
2018-01-30 21:56:30 +00:00
def __str__(self):
return self.name
class Content(models.Model):
"""Un contenu du site (vidéo)."""
name = models.CharField(
max_length=255,
2018-01-24 10:33:05 +00:00
verbose_name="Nom du contenu"
)
2018-02-28 20:25:44 +00:00
school_owner = models.ForeignKey(
SchoolProfile,
on_delete=models.CASCADE,
)
2018-01-24 10:33:05 +00:00
category = models.ForeignKey(
Category,
on_delete=models.SET_NULL,
verbose_name="Catégorie",
null=True
)
2018-02-28 20:25:44 +00:00
file = models.FileField(
verbose_name="Fichier"
)
2018-01-30 21:56:30 +00:00
def __str__(self):
return self.name
2018-03-02 09:28:31 +00:00
def manager_right(self):
return 'users.manage_' + str(self.school_owner.group.pk)