2015-03-17 19:03:51 +01:00
|
|
|
from django.db import models
|
|
|
|
import os
|
|
|
|
|
|
|
|
import Ernestophone.settings
|
|
|
|
|
2016-06-21 09:49:45 +02:00
|
|
|
PARTITION_TYPES = (
|
2016-06-22 14:09:41 +02:00
|
|
|
("active", "Actif"),
|
|
|
|
("incoming", "À venir"),
|
|
|
|
("old", "Archive"),
|
2016-06-21 09:49:45 +02:00
|
|
|
)
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
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):
|
2016-07-14 01:58:52 +02:00
|
|
|
os.remove(os.path.join(Ernestophone.settings.MEDIA_ROOT,
|
|
|
|
self.part.name))
|
2015-03-17 19:03:51 +01:00
|
|
|
super(Partition, self).delete(*args, **kwargs)
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
class PartitionSet(models.Model):
|
|
|
|
nom = models.CharField(max_length=100)
|
|
|
|
auteur = models.CharField(max_length=100)
|
2016-06-21 09:49:45 +02:00
|
|
|
category = models.CharField('Types de partitions', max_length=8,
|
2016-07-14 01:58:52 +02:00
|
|
|
choices=PARTITION_TYPES, default="incoming")
|
2016-06-22 17:34:27 +02:00
|
|
|
infos = models.TextField("Infos utiles", null=True, blank=True)
|
2015-03-17 19:03:51 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-06-22 14:09:41 +02:00
|
|
|
return("%s - %s [%s]" % (self.nom, self.auteur,
|
2016-07-14 01:58:52 +02:00
|
|
|
self.get_category_display()))
|