24 lines
900 B
Python
24 lines
900 B
Python
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
from users.models import Agency
|
|
# Create your models here.
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
|
|
|
|
def user_directory_path(instance, filename):
|
|
# file will be uploaded to MEDIA_ROOT/agency_<id>/<subdirs>/<filename>
|
|
return 'agency_{0}/{1}/{2}'.format(instance.agency.pk, instance.subdir, filename)
|
|
|
|
|
|
class Data(models.Model):
|
|
subdir = models.CharField(max_length=2000, default="", blank=True, null=True)
|
|
file = models.FileField(null=True, max_length=255, upload_to=user_directory_path)
|
|
date_created = models.DateTimeField(default = timezone.now)
|
|
date_last_modified = models.DateTimeField(default = timezone.now)
|
|
owner = models.ForeignKey(User, on_delete=models.PROTECT)
|
|
agency = models.ForeignKey(Agency, on_delete=models.CASCADE, default=None)
|
|
|
|
def __str__(self):
|
|
return str(self.file.name)
|