Commit 6d18e81b authored by Ciella Francisco's avatar Ciella Francisco 😵

Enabled renaming of images filename once uploaded in creating an event

parent 7f986bdc
import os
from django.db import models from django.db import models
from django_resized import ResizedImageField from django_resized import ResizedImageField
from django.utils import timezone from django.utils import timezone
from django.urls import reverse from django.urls import reverse
from accounts import models as accounts from accounts import models as accounts
from uuid import uuid4
# from datetime import timedelta # from datetime import timedelta
class Event(models.Model): class Event(models.Model):
def rename_image(path):
def wrapper(instance, filename):
ext = filename.split('.')[-1]
# get filename
if instance.pk:
filename = 'event{}header.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(path, filename)
return wrapper
event_name = models.CharField(default='', max_length=150) event_name = models.CharField(default='', max_length=150)
event_datetime_start = models.DateTimeField(default=timezone.now, null=False) event_datetime_start = models.DateTimeField(default=timezone.now, null=False)
event_datetime_end = models.DateTimeField(default=None, null=True) event_datetime_end = models.DateTimeField(default=None, null=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment