2020-05-27 13:06:38 +00:00
|
|
|
from django.db.models import Model, ImageField, FileField, ManyToManyField, ForeignKey, BooleanField, CASCADE
|
2020-04-16 13:22:03 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
|
|
|
from polymorphic.models import PolymorphicModel
|
2020-04-13 10:08:59 +00:00
|
|
|
|
|
|
|
from core.helpers.files import generate_storage_filename
|
2020-04-16 13:22:03 +00:00
|
|
|
from core.models.profiles import Profile
|
2020-05-27 13:06:38 +00:00
|
|
|
from core.fields.base import LongCharField
|
2020-04-13 10:08:59 +00:00
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
2020-04-16 13:22:03 +00:00
|
|
|
class BaseFile(PolymorphicModel):
|
2020-05-27 13:06:38 +00:00
|
|
|
filename = LongCharField()
|
2020-04-13 10:08:59 +00:00
|
|
|
|
2020-06-02 15:58:20 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.filename
|
|
|
|
|
2020-04-16 13:22:03 +00:00
|
|
|
class ImageFile(BaseFile):
|
|
|
|
rawfile = ImageField(upload_to=generate_storage_filename)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def get_file(self):
|
2020-06-02 15:58:20 +00:00
|
|
|
return self.rawfile
|
2020-04-16 13:22:03 +00:00
|
|
|
|
|
|
|
class File(BaseFile):
|
|
|
|
rawfile = FileField(upload_to=generate_storage_filename)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def get_file(self):
|
2020-06-02 15:58:20 +00:00
|
|
|
return self.rawfile
|
2020-04-16 13:22:03 +00:00
|
|
|
|
|
|
|
class FileAssociation(Model):
|
|
|
|
file = ForeignKey(BaseFile, CASCADE)
|
|
|
|
user = ForeignKey(get_user_model(), CASCADE)
|
|
|
|
visible = BooleanField()
|