The project I have has events and the back end is Django and the front end is Vue.
I have this event model:
from datetime import datetime
from django.db import models
from locations.models import Location
from django.contrib.auth import get_user_model
from multiselectfield import MultiSelectField
User = get_user_model()
class RepeatDate(models.Model):
date = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = "repeat date"
verbose_name_plural = "repeat dates"
ordering = ['date']
db_table = "event_repeat_dates"
class Venue(models.Model):
name = models.CharField(max_length=50)
location = models.ForeignKey(Location, on_delete=models.CASCADE, default=None)
created_at = models.DateTimeField(auto_now_add=True, verbose_name="created at")
updated_at = models.DateTimeField(auto_now=True, verbose_name="updated at")
class Meta:
verbose_name = "venue"
verbose_name_plural = "venues"
ordering = ['name']
db_table = "venues"
def __str__(self):
return self.name
class Event(models.Model):
AUCT = 'AUCT'
CONF = 'CONF'
COMU = 'COMU'
DANC = 'DANC'
CLUB = 'CLUB'
CONC = 'CONC'
MARK = 'MARK'
TRAD = 'TRAD'
FEST = 'FEST'
STAG = 'STAG'
SPOR = 'SPOR'
ONLI = 'ONLI'
WORK = 'WORK'
TYPES = [
(AUCT, 'Auction'),
(CONF, 'Conference'),
(COMU, 'Community'),
(DANC, 'Dance'),
(CLUB, 'Club'),
(CONC, 'Concert'),
(MARK, 'Market'),
(TRAD, 'Trade'),
(FEST, 'Festival'),
(STAG, 'Stage'),
(SPOR, 'Sports'),
(ONLI, 'Online'),
(WORK, 'Workshop'),
]
DA = 'DA'
WE = 'WE'
MO = 'MO'
QU = 'QU'
BI = 'BI'
AN = 'AN'
INTERVAL = [
(DA, 'Daily'),
(WE, 'Weekly'),
(MO, 'Monthly'),
(QU, 'Quarterly'),
(BI, 'Biannually'),
(AN, 'Annually'),
]
MO = 'MO'
TU = 'TU'
WE = 'WE'
TH = 'TH'
FR = 'FR'
SA = 'SA'
SU = 'SU'
DAYS = [
(MO, 'Monday'),
(TU, 'Tuesday'),
(WE, 'Wednesday'),
(TH, 'Thursday'),
(FR, 'Friday'),
(SA, 'Saturday'),
(SU, 'Sunday'),
]
name = models.CharField(max_length=150, verbose_name="event name")
type = models.CharField(max_length=4, choices=TYPES, default=None)
repeat = models.BooleanField(default=False)
interval = models.CharField(max_length=2, choices=INTERVAL, null=True, blank=True)
repeating_days = MultiSelectField(max_length=2, choices=DAYS, null=True, blank=True)
repeating_dates = models.ForeignKey(RepeatDate, on_delete=models.CASCADE, null=True, blank=True)
startdate = models.DateTimeField(auto_now=True, verbose_name="start date")
enddate = models.DateTimeField(auto_now=True, verbose_name="start date")
image = models.FileField(
upload_to="events/images", blank=True, null=True
)
description = models.TextField(max_length=5000)
venue = models.ForeignKey(Venue, on_delete=models.CASCADE, default=None)
published = models.BooleanField(default=True)
pinned = models.BooleanField(default=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
created_at = models.DateTimeField(auto_now_add=True, verbose_name="created at")
updated_at = models.DateTimeField(auto_now=True, verbose_name="updated at")
class Meta:
verbose_name = "event"
verbose_name_plural = "events"
ordering = ['startdate']
db_table = "events"
def __str__(self):
return self.name
Events can repeat and a user can select if an event repeats and whether if repeats every day every week or every month or on selected dates. The select dates in that case will be a mutli-select calendar on the front end. How do I save the data in the back-end and what type of field should I use for that please. At the moment I have a foreign key called repeat dates for a table with the same name but I am not sure if that is going to work correctly so looking for some advice pls.