models.py 1.92 KB
Newer Older
1
from django.db import models
Tyler Hallada's avatar
Tyler Hallada committed
2 3
from django.core.cache import cache

4 5

class Restaurant(models.Model):
Tyler Hallada's avatar
Tyler Hallada committed
6 7 8 9 10
    name = models.CharField(max_length=100)
    mainSchedule = models.ForeignKey('Schedule',
            related_name='restaurant_main')
    specialSchedules = models.ManyToManyField('Schedule',
            related_name='restaurant_special', null=True, blank=True)
11

Tyler Hallada's avatar
Tyler Hallada committed
12 13 14
    def save(self, *args, **kwargs):
        cache.clear()  # Invalidate cache on restaurant change/creation
        super(Restaurant, self).save(*args, **kwargs)
15

Tyler Hallada's avatar
Tyler Hallada committed
16 17 18
    def delete(self, *args, **kwargs):
        cache.clear()  # Invalidate cache on restuarant deletion
        super(Restaurant, self).delete(*args, **kwargs)
19 20


Tyler Hallada's avatar
Tyler Hallada committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
class Schedule(models.Model):
    name = models.CharField(max_length=100)
    dateValidStart = models.DateField(null=True, blank=True)
    dateValidEnd = models.DateField(null=True, blank=True)
    monOpen = models.TimeField(null=True, blank=True)
    monClose = models.TimeField(null=True, blank=True)
    tueOpen = models.TimeField(null=True, blank=True)
    tueClose = models.TimeField(null=True, blank=True)
    wedOpen = models.TimeField(null=True, blank=True)
    wedClose = models.TimeField(null=True, blank=True)
    thuOpen = models.TimeField(null=True, blank=True)
    thuClose = models.TimeField(null=True, blank=True)
    friOpen = models.TimeField(null=True, blank=True)
    friClose = models.TimeField(null=True, blank=True)
    satOpen = models.TimeField(null=True, blank=True)
    satClose = models.TimeField(null=True, blank=True)
    sunOpen = models.TimeField(null=True, blank=True)
    sunClose = models.TimeField(null=True, blank=True)
39

Tyler Hallada's avatar
Tyler Hallada committed
40 41 42
    def save(self, *args, **kwargs):
        cache.clear()  # Invalidate cache on schedule change/creation
        super(Schedule, self).save(*args, **kwargs)
43

Tyler Hallada's avatar
Tyler Hallada committed
44 45 46
    def delete(self, *args, **kwargs):
        cache.clear()  # Invalidate cache on schedule deletion
        super(Schedule, self).delete(*args, **kwargs)