model.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import peewee
  2. import lc.config
  3. class Model(peewee.Model):
  4. class Meta:
  5. database = lc.config.DB
  6. # TODO: figure out authorization for users (oauth? passwd?)
  7. class User(Model):
  8. '''
  9. A user! you know tf this is about
  10. '''
  11. name = peewee.TextField()
  12. class Link(Model):
  13. '''
  14. A link as stored in the database
  15. '''
  16. url = peewee.TextField()
  17. name = peewee.TextField()
  18. description = peewee.TextField()
  19. # TODO: do we need to track modified time?
  20. created = peewee.DateTimeField()
  21. # is the field entirely private?
  22. private = peewee.BooleanField()
  23. class Tag(Model):
  24. '''
  25. A tag. This just indicates that a user has used this tag at some point.
  26. '''
  27. name = peewee.TextField()
  28. parent = peewee.ForeignKeyField('self', null=True, backref='children')
  29. class HasTag(Model):
  30. '''
  31. Establishes that a link is tagged with a given tag.
  32. '''
  33. link = peewee.ForeignKeyField(Link, backref='tags')
  34. tag = peewee.ForeignKeyField(Tag, backref='models')
  35. MODELS = [
  36. User,
  37. Link,
  38. Tag,
  39. HasTag,
  40. ]
  41. def create_tables():
  42. lc.config.DB.create_tables(MODELS, safe=True)