from sqlalchemy import Column, Integer, String, ForeignKey, Sequence, Text, DateTime
from sqlalchemy.orm import relationship
from .database import Base
from datetime import datetime
import bcrypt

class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
    username = Column(String(32), unique=True)
    password = Column(String(64))
    group_id = Column(Integer, ForeignKey('groups.id'))
    created = Column(DateTime)
    last_logged_on = Column(DateTime)

    group = relationship("Group", back_populates="users")

    def __init__(self, username, password=None):
        self.username = username
        self.password = bcrypt.hashpw(password, bcrypt.gensalt(14))
        self.group_id = 1
		self.created = datetime.utcnow()
		self.last_logged_on = datetime.utcnow()

    def is_authenticated(self):
        return True
 
    def is_active(self):
        return True
 
    def is_anonymous(self):
        return False
 
    def get_id(self):
        return unicode(self.id)
 
    def __repr__(self):
        return '<User %r>' % (self.username)

class Group(Base):
    __tablename__ = 'groups'

    id = Column(Integer, Sequence('group_id_seq'), primary_key=True)
    name = Column(String(32), unique=True)
    description = Column(Text)

    def __init__(self, name, description=None):
        self.name = name
        self.description = description

    def __repr__(self):
        return '<Usergroup %r>' % (self.name)

class Answer(Base):
    __tablename__ = 'answers'

    id = Column(Integer, Sequence('answer_id_seq'), primary_key=True)
    answer = Column(Text, unique=True)

    def __init__(self, answer=None):
        self.answer = answer

    def __repr__(self):
        return '<Answer %r>' % (self.name)

class Question(Base):
    __tablename__ = 'questions'

    id = Column(Integer, Sequence('question_id_seq'), primary_key=True)
    question = Column(String(120))
    answer = Column(Integer, ForeignKey('answers.id'))
    correct_answer = Column(Integer, ForeignKey('answers.id'))
    times_correct = Column(Integer)
    attempts = Column(Integer)

    answer_id = relationship('Answer', back_populates="questions")
    correct_answer_id = relationship('Answer', back_populates="questions")

    def __init__(self, question, answer, correct_answer=None):
        self.question = question
        self.answer = answer
		self.correct_answer = correct_answer
		self.times_correct = 0
		self.attempts = 0

    def __repr__(self):
        return '<Question %r>' % (self.question)

@@ -190,16 +190,17 @@
 bcrypt%0A%0A
+%0A
 class Us
@@ -748,18 +748,24 @@
 _id = 1%0A
-%09%09
+        
 self.cre
@@ -789,18 +789,24 @@
 tcnow()%0A
-%09%09
+        
 self.las
@@ -838,20 +838,17 @@
 cnow()%0A%0A
-    
+%0A
 def is_a
@@ -863,36 +863,32 @@
 ated(self):%0A    
-  
-  
 return True%0A %0A  
@@ -875,38 +875,34 @@
     return True%0A
- %0A    
+%0A%0A
 def is_active(se
@@ -898,36 +898,32 @@
 s_active(self):%0A
-    
     return True%0A
@@ -922,22 +922,18 @@
 rn True%0A
- %0A    
+%0A%0A
 def is_a
@@ -940,36 +940,32 @@
 nonymous(self):%0A
-    
     return False
@@ -965,22 +965,18 @@
 n False%0A
- %0A    
+%0A%0A
 def get_
@@ -977,36 +977,32 @@
 f get_id(self):%0A
-    
     return unico
@@ -1017,14 +1017,10 @@
 id)%0A
- %0A    
+%0A%0A
 def 
@@ -1027,36 +1027,32 @@
 __repr__(self):%0A
-    
     return '%3CUse
@@ -1073,24 +1073,25 @@
 .username)%0A%0A
+%0A
 class Group(
@@ -1451,24 +1451,25 @@
 self.name)%0A%0A
+%0A
 class Answer
@@ -1752,16 +1752,17 @@
 .name)%0A%0A
+%0A
 class Qu
@@ -2365,26 +2365,32 @@
 er = answer%0A
-%09%09
+        
 self.correct
@@ -2414,18 +2414,24 @@
 _answer%0A
-%09%09
+        
 self.tim
@@ -2449,10 +2449,16 @@
 = 0%0A
-%09%09
+        
 self
@@ -2472,20 +2472,17 @@
 ts = 0%0A%0A
-    
+%0A
 def __re
@@ -2485,36 +2485,32 @@
 __repr__(self):%0A
-    
     return '%3CQue

Fix indentation (tabs->spaces)