"""
Models for the Jukebox application

User - All users
Vote - Votes on songs
"""

import logging

from peewee import SqliteDatabase, Model, CharField, DateTimeField, ForeignKeyField

db = SqliteDatabase(None)
logger = logging.getLogger(__name__)


class User(Model):
    name = CharField()

    @staticmethod
    def current():
        return User.get(User.name == 'q')

    class Meta:
        database = db


class Vote(Model):
    # references a Mopidy track
    track_uri = CharField()
    user = ForeignKeyField(User, related_name='voter')
    timestamp = DateTimeField()

    class Meta:
        database = db


def init(db_file):
    # Create db
    db.init(db_file)

    # Create tables
    if not Vote.table_exists():
        Vote.create_table()
    if not User.table_exists():
        User.create_table()
        # create dummy user
        User(name="q").save()

@@ -77,16 +77,32 @@
 gs%0A%22%22%22%0A%0A
+import datetime%0A
 import l
@@ -192,16 +192,27 @@
 KeyField
+, UUIDField
 %0A%0Adb = S
@@ -293,20 +293,107 @@
 l):%0A    
-name
+id = CharField(primary_key=True)%0A    name = CharField()%0A    picture = CharField()%0A    email
  = CharF
@@ -727,16 +727,253 @@
  = db%0A%0A%0A
+class Session(Model):%0A    user = ForeignKeyField(User)%0A    secret = UUIDField()%0A    expires = DateTimeField(default=datetime.datetime.now() + datetime.timedelta(days=30))  # expires after 30 days%0A%0A    class Meta:%0A        database = db%0A%0A%0A
 def init
@@ -1169,58 +1169,66 @@
     
-    # create dummy user%0A        User(name=%22q%22).sav
+if not Session.table_exists():%0A        Session.create_tabl
 e()%0A

Create model for session, add properties for user