from django.db import models
from django.contrib.auth.models import User
from dynamic_filenames import FilePattern

# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length=75)
    body = models.TextField()
    slug = models.SlugField()
    date = models.DateTimeField(auto_now_add=True)
    banner = models.ImageField(default='fallback.png', blank=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE, default=None) #Kritisch wenn conus medical products are linked to User.objects.get(username='root')company and compony is deleted all products are deleted.

    def __str__(self):
        return self.title
    
def user_directory_path(instance, filename):
    return "user_{0}/{1}".format(instance.user.id, filename)

upload_to_pattern = FilePattern(filename_pattern='PDFuploads/{app_label:.25}/{model_name:.30}/{uuid:base32}{ext}')
class ConusFilePDF(models.Model):
    fileName = models.CharField(max_length=32)
    #file = models.FileField(upload_to="PDFuploads/")
    file = models.FileField(upload_to=upload_to_pattern)