expephalon-kumisms/core/models/files.py
Klaus-Uwe Mitterer 53780751d1 Preparing files for admin profiles
Changing File models to allow user association
2020-04-16 15:22:03 +02:00

31 lines
No EOL
876 B
Python

from django.db.models import Model, CharField, ImageField, FileField, ManyToManyField, ForeignKey, BooleanField, CASCADE
from django.contrib.auth import get_user_model
from polymorphic.models import PolymorphicModel
from core.helpers.files import generate_storage_filename
from core.models.profiles import Profile
# Create your models here.
class BaseFile(PolymorphicModel):
filename = CharField(max_length=255)
class ImageFile(BaseFile):
rawfile = ImageField(upload_to=generate_storage_filename)
@property
def get_file(self):
return self.image
class File(BaseFile):
rawfile = FileField(upload_to=generate_storage_filename)
@property
def get_file(self):
return self.file
class FileAssociation(Model):
file = ForeignKey(BaseFile, CASCADE)
user = ForeignKey(get_user_model(), CASCADE)
visible = BooleanField()