from datetime import date
from django.conf import settings
from django.db import models


# Create your models here.
def user_directory_path(instance, filename):
    # file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
    today = date.today()
    return '{0}/{2}/{1}'.format(instance.user.username, filename, today.strftime("%Y/%m/%d/"))


class Upload(models.Model):
    uploaded_file = models.FileField(null=True, blank=True, upload_to=user_directory_path)
    file_name = models.CharField(max_length=255, null=True)
    date_uploaded = models.DateField(auto_now_add=True, null=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)

    def __str__(self):
        return self.uploaded_file.name

[((237, 249), 'datetime.date.today', 'date.today', ([], {}), '()\n', (247, 249), False, 'from datetime import date\n'), ((395, 465), 'django.db.models.FileField', 'models.FileField', ([], {'null': '(True)', 'blank': '(True)', 'upload_to': 'user_directory_path'}), '(null=True, blank=True, upload_to=user_directory_path)\n', (411, 465), False, 'from django.db import models\n'), ((482, 525), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(255)', 'null': '(True)'}), '(max_length=255, null=True)\n', (498, 525), False, 'from django.db import models\n'), ((546, 592), 'django.db.models.DateField', 'models.DateField', ([], {'auto_now_add': '(True)', 'null': '(True)'}), '(auto_now_add=True, null=True)\n', (562, 592), False, 'from django.db import models\n'), ((604, 689), 'django.db.models.ForeignKey', 'models.ForeignKey', (['settings.AUTH_USER_MODEL'], {'on_delete': 'models.CASCADE', 'null': '(True)'}), '(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True\n    )\n', (621, 689), False, 'from django.db import models\n')]