Skip to content

Instantly share code, notes, and snippets.

@pwwilson
Created July 31, 2015 01:03
Show Gist options
  • Save pwwilson/03b63bd1d7a72dc16c83 to your computer and use it in GitHub Desktop.
Save pwwilson/03b63bd1d7a72dc16c83 to your computer and use it in GitHub Desktop.
import uuid
from django.db import models
from django_extensions.db.fields.json import JSONField
from djorm_pgarray.fields import TextArrayField
from django.contrib.auth.models import User
# you could make a monkuser class and use the standard user model to only handle auth
# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
class BaseObject(models.Model):
name = models.CharField(max_length=80)
addTime = models.DateTimeField()
modTime = models.DateTimeField()
lastModifiedBy = models.OneToOneField(User, null=True) # s/b MonkUser?
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Meta:
abstract = True
class MonkUser(BaseObject):
# todo: user = models.ForeignKey(User)
email = models.EmailField(unique=True)
class Meta:
ordering = ('name',)
def __unicode__(self):
return '<%s> %s' % (self.name, self.email)
class OwnedObject(BaseObject):
# Parent (abstract) object for the Notes and Entries.
owner = models.ForeignKey(MonkUser, related_name='%(class)s_set', null=True, help_text="Reference to Object's Owner")
class Meta:
abstract = True
class Site(OwnedObject):
borders = JSONField()
skybox = models.OneToOneField(SkyBox)
sprites = TextArrayField() # or JSON or toMany?
tour = models.OneToOneField(Tour)
class Sprite(OwnedObject):
geometry = models.URLField()
height = models.FloatField()
texture = models.URLField()
type = models.CharField(max_length=80)
# Many to One use ForeignKey
assets = JSONField() # or models.ForeignKey(Asset)
label = JSONField() # models.ForeignKey(Label) # one to one
levels = JSONField() # models.ForeignKey(Levels) # to many
location = models.ForeignKey(Location)
class Asset(OwnedObject):
path = models.URLField()
type = models.CharField(max_length=80)
votes = models.ForeignKey(Vote)
class Location(OwnedObject):
latitude = models.DecimalField(max_digits=12, decimal_places=9)
longitude = models.DecimalField(max_digits=12, decimal_places=9)
class Vote(OwnedObject):
weight = models.IntegerField()
asset = models.OneToOneField(Asset)
class SkyBox(OwnedObject):
asset = models.OneToOneField(Asset)
class Tour():
isPublic = models.BooleanField(default=True, help_text="Boolean flag indicating if this Tour is public or is a private (paid) tour.")
sharedWith = models.ManyToManyField(MonkUser, related_name='shared_tours', blank=True, null=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment