ernestophone.ens.fr/partitions/models.py

44 lines
1.2 KiB
Python
Raw Normal View History

2015-03-17 19:03:51 +01:00
import os
2017-10-13 15:01:17 +02:00
from django.conf import settings
from django.db import models
2015-03-17 19:03:51 +01:00
2018-01-04 20:20:30 +01:00
class Category(models.Model):
name = models.CharField(max_length=127)
order = models.IntegerField(verbose_name="order")
def __str__(self):
return self.name
class Meta:
verbose_name = "catégorie"
verbose_name_plural = "catégories"
2015-03-17 19:03:51 +01:00
class Partition(models.Model):
nom = models.CharField(max_length=100)
part = models.FileField(upload_to="partitions/")
2018-01-04 23:43:10 +01:00
morceau = models.ForeignKey('PartitionSet', on_delete=models.CASCADE)
2015-03-17 19:03:51 +01:00
def __str__(self):
return self.nom
def delete(self, *args, **kwargs):
2017-10-13 15:01:17 +02:00
os.remove(os.path.join(settings.MEDIA_ROOT, self.part.name))
2015-03-17 19:03:51 +01:00
super(Partition, self).delete(*args, **kwargs)
2015-03-17 19:03:51 +01:00
class PartitionSet(models.Model):
nom = models.CharField(max_length=100)
auteur = models.CharField(max_length=100)
2018-01-04 20:20:30 +01:00
category = models.ForeignKey(
Category,
on_delete=models.PROTECT,
verbose_name="Type de partition"
)
infos = models.TextField("Infos utiles", null=True, blank=True)
2015-03-17 19:03:51 +01:00
def __str__(self):
2018-01-04 20:20:30 +01:00
return("%s - %s [%s]" % (self.nom, self.auteur, self.category))