2021-06-07 17:26:07 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
2021-06-06 22:25:10 +02:00
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Table
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
|
|
|
|
user_skill_table = Table("user_skill", db.Model.metadata,
|
|
|
|
Column("user_id", Integer, ForeignKey("user.id")),
|
|
|
|
Column("skill_id", Integer, ForeignKey("skill.id")))
|
|
|
|
|
2021-06-07 17:26:07 +02:00
|
|
|
user_language_table = Table(
|
|
|
|
"user_language", db.Model.metadata,
|
|
|
|
Column("user_id", Integer, ForeignKey("user.id")),
|
|
|
|
Column("language_id", Integer, ForeignKey("language.id")))
|
|
|
|
|
2021-06-06 22:25:10 +02:00
|
|
|
|
|
|
|
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="")
|
2021-06-07 17:26:07 +02:00
|
|
|
created = Column(DateTime, nullable=False)
|
|
|
|
updated = Column(DateTime, onupdate=datetime.now, nullable=False)
|
2021-06-06 22:25:10 +02:00
|
|
|
|
2021-06-07 17:26:07 +02:00
|
|
|
contacts = relationship("Contact")
|
|
|
|
address = relationship("Address", uselist=False, back_populates="user")
|
2021-06-06 22:25:10 +02:00
|
|
|
skills = relationship("Skill",
|
|
|
|
secondary=user_skill_table,
|
|
|
|
back_populates="users")
|
2021-06-07 17:26:07 +02:00
|
|
|
languages = relationship("Language",
|
|
|
|
secondary=user_language_table,
|
|
|
|
back_populates="users")
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2021-06-06 22:25:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
secondary=user_skill_table,
|
|
|
|
back_populates="skills")
|
|
|
|
|
|
|
|
|
|
|
|
class Language(db.Model):
|
|
|
|
__tablename__ = "language"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
name = Column(String(25), nullable=False)
|
2021-06-07 17:26:07 +02:00
|
|
|
|
|
|
|
users = relationship("User",
|
|
|
|
secondary=user_language_table,
|
|
|
|
back_populates="languages")
|