115 lines
3.5 KiB
Python
115 lines
3.5 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, Integer, SmallInteger, String, DateTime, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app import db
|
|
|
|
|
|
class User(db.Model):
|
|
__tablename__ = "user"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
nickname = Column(String(25), unique=True, nullable=False)
|
|
pronouns = Column(String(25), default="")
|
|
volunteerwork = Column(String(4000), default="")
|
|
freetext = Column(String(4000), default="")
|
|
created = Column(DateTime, nullable=False)
|
|
updated = Column(DateTime, onupdate=datetime.now, nullable=False)
|
|
auth_id = Column(String(50), nullable=False)
|
|
|
|
contacts = relationship("Contact")
|
|
address = relationship("Address", uselist=False, back_populates="user")
|
|
tokens = relationship("Token", uselist=False, back_populates="user")
|
|
skills = relationship("UserSkill", back_populates="users")
|
|
languages = relationship("UserLanguage", "users")
|
|
|
|
|
|
class Token(db.Model):
|
|
__tablename__ = "token"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
user_id = Column(Integer, ForeignKey("user.id"))
|
|
token = Column(String(36), nullable=False)
|
|
|
|
user = relationship("User", back_populates="tokens")
|
|
|
|
|
|
class Contact(db.Model):
|
|
__tablename__ = "contact"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
user_id = Column(Integer, ForeignKey("user.id"))
|
|
user = relationship("User", back_populates="contacts")
|
|
contacttype_id = Column(Integer, ForeignKey("contacttype.id"))
|
|
contacttype = relationship("ContactType")
|
|
content = Column(String(200), nullable=False)
|
|
|
|
|
|
class ContactType(db.Model):
|
|
__tablename__ = "contacttype"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
name = Column(String(25), nullable=False)
|
|
|
|
|
|
class Address(db.Model):
|
|
__tablename__ = "address"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
street = Column(String(25), default="")
|
|
house_number = Column(String(10), default="")
|
|
additional = Column(String(25), default="")
|
|
postcode = Column(String(10), default="")
|
|
city = Column(String(25), default="")
|
|
country = Column(String(25), default="")
|
|
|
|
user_id = Column(Integer, ForeignKey("user.id"))
|
|
user = relationship("User", back_populates="address")
|
|
|
|
|
|
class Skill(db.Model):
|
|
__tablename__ = "skill"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
name = Column(String(25), unique=True, nullable=False)
|
|
|
|
users = relationship("User", back_populates="skills")
|
|
|
|
def to_dict(self):
|
|
return {"id": self.id, "name": self.name}
|
|
|
|
|
|
class UserSkill(db.Model):
|
|
__tablename__ = "user_skill"
|
|
|
|
user_id = Column(Integer, ForeignKey("user.id"), primary_key=True)
|
|
skill_id = Column(Integer, ForeignKey("skill.id"), primary_key=True)
|
|
level = Column(SmallInteger, nullable=False)
|
|
|
|
user = relationship("User", back_populates="skills")
|
|
skill = relationship("Skill", back_populates="users")
|
|
|
|
|
|
class Language(db.Model):
|
|
__tablename__ = "language"
|
|
|
|
id = Column(String(2), primary_key=True)
|
|
name = Column(String(25), nullable=False)
|
|
|
|
users = relationship("UserLanguage", back_populates="languages")
|
|
|
|
def to_dict(self):
|
|
return {"id": self.id, "name": self.name}
|
|
|
|
|
|
class UserLanguage(db.Model):
|
|
__tablename__ = "user_language"
|
|
|
|
user_id = Column(Integer, ForeignKey("user.id"), primary_key=True)
|
|
language_id = Column(Integer, ForeignKey("language.id"), primary_key=True)
|
|
level = Column(SmallInteger, nullable=False)
|
|
|
|
user = relationship("User", back_populates="languages")
|
|
language = relationship("Language", back_populates="users")
|