ernestophone.ens.fr/partitions/models.py
2018-05-01 10:09:50 +02:00

43 lines
1.2 KiB
Python

import os
from django.conf import settings
from django.db import models
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"
class Partition(models.Model):
nom = models.CharField(max_length=100)
part = models.FileField(upload_to="partitions/")
morceau = models.ForeignKey('PartitionSet', on_delete=models.CASCADE)
def __str__(self):
return self.nom
def delete(self, *args, **kwargs):
os.remove(os.path.join(settings.MEDIA_ROOT, self.part.name))
super(Partition, self).delete(*args, **kwargs)
class PartitionSet(models.Model):
nom = models.CharField(max_length=100)
auteur = models.CharField(max_length=100)
category = models.ForeignKey(
Category,
on_delete=models.PROTECT,
verbose_name="Type de partition"
)
infos = models.TextField("Infos utiles", null=True, blank=True)
def __str__(self):
return("%s - %s [%s]" % (self.nom, self.auteur, self.category))