SHARE
TWEET

Untitled

a guest Jun 4th, 2017 162 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.db import models
  2.  
  3. _weekdays = {
  4.     0 : 'M',
  5.     1 : 'T',
  6.     2 : 'W',
  7.     3 : 'R',
  8.     4 : 'F',
  9.     5 : 'Sa',
  10.     6 : 'Su',
  11. }
  12.  
  13. class Lot(models.Model):
  14.     name = models.CharField(primary_key=True, max_length=50)
  15.     description = models.CharField(max_length=50)
  16.     lat = models.DecimalField(max_digits=8, decimal_places=6)
  17.     lng = models.DecimalField(max_digits=8, decimal_places=6)
  18.     times = models.ManyToManyField('ParkTime', through='ParkRule')
  19.  
  20.     def toJSON(self):
  21.         return {
  22.             'name' : self.name,
  23.             'description' : self.description,
  24.             'lat' : float(self.lat),
  25.             'lng' : float(self.lng),
  26.         }  
  27.  
  28.     def __unicode__(self):
  29.         return u'%s' % (self.name)
  30.  
  31. class Tag(models.Model):
  32.     name = models.CharField(primary_key=True, max_length=5)
  33.     lots = models.ManyToManyField('ParkTime', through='ParkRule')
  34.  
  35.     def __unicode__(self):
  36.         return u'%s' % (self.name)
  37.  
  38. class ParkTime(models.Model):
  39.     start = models.TimeField()
  40.     end = models.TimeField()
  41.     days = models.ManyToManyField('Weekday')
  42.  
  43.     def __unicode__(self):
  44.         (startStr, endStr) = (self.start.strftime("%H:%M"), self.end.strftime("%H:%M"))
  45.         daysStr = ''.join([str(day) for day in self.days.all()])
  46.         return u'%s - %s %s' % (startStr, endStr, daysStr)
  47.  
  48. class ParkRule(models.Model):
  49.     lot = models.ForeignKey(Lot)
  50.     tag = models.ForeignKey(Tag)
  51.     when = models.ForeignKey(ParkTime)
  52.     canPark = models.BooleanField()
  53.     takesEffect = models.DateField()
  54.     lastsUntil = models.DateField()
  55.  
  56.     def __unicode__(self):
  57.         return u'%s in %s: %s' % (self.tag, self.lot, self.when)
  58.  
  59. class Weekday(models.Model):
  60.     day = models.IntegerField()
  61.  
  62.     def __unicode__(self):
  63.         return u'%s' % (_weekdays[self.day])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top