from django.db import models import os import Ernestophone.settings PARTITION_TYPES = ( ("active", "Actif"), ("incoming", "À venir"), ("old", "Archive"), ) class Partition(models.Model): nom = models.CharField(max_length=100) part = models.FileField(upload_to="partitions/") morceau = models.ForeignKey('PartitionSet') def __str__(self): return self.nom def delete(self, *args, **kwargs): os.remove(os.path.join(Ernestophone.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.CharField('Types de partitions', max_length=8, choices=PARTITION_TYPES, default="incoming") infos = models.TextField("Infos utiles", null=True, blank=True) def __str__(self): return("%s - %s [%s]" % (self.nom, self.auteur, self.get_category_display()))