models.py 3.34 KB
Newer Older
1
from django.db import models
2
import datetime
3 4

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

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    #function
    #def analyzer(dayOpen, dayClose):
    #   if dayOpen is null or dayClose is null:
    #       return False
    #   elif timeNow >= dayOpen and timeNow <= dayClose:
    #       return True
    #   else:
    #       return False

    def isOpen():
        timeNow = datetime.datetime.now().time()
        day = datetime.date.today().weekday()
        if day is 1:
            if monOpen is null or monClose is null:
                return False
            elif timeNow >= monOpen and timeNow <= monClose:
                return True
            else:
                return False
        elif day is 2:
            if tueOpen is null or tueClose is null:
                return False
            elif timeNow >= tueOpen and timeNow <= tueClose:
                return True
            else:
                return False
        elif day is 3:
            if wedOpen is null or wedClose is null:
                return False
            elif timeNow >= wedOpen and timeNow <= wedClose:
                return True
            else:
                return False
        elif day is 4:
            if thuOpen is null or thuClose is null:
                return False
            elif timeNow >= thuOpen and timeNow <= thuClose:
                return True
            else:
                return False
        elif day is 5:
            if friOpen is null or friClose is null:
                return False
            elif timeNow >= friOpen and timeNow <= friClose:
                return True
            else:
                return False
        elif day is 6:
            if satOpen is null or satClose is null:
                return False
            elif timeNow >= satOpen and timeNow <= satClose:
                return True
            else:
                return False
        elif day is 7:
            if sunOpen is null or sunClose is null:
                return False
            elif timeNow >= sunOpen and timeNow <= sunClose:
                return True
            else:
                return False

    #def isC`losing:



75
class Schedule(models.Model):
Daniel Bond's avatar
Daniel Bond committed
76
    name = models.CharField(max_length = 100)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    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)