Improvements
This commit is contained in:
parent
4e5ee195dd
commit
a0df624f16
14 changed files with 1021 additions and 59 deletions
|
|
@ -3,6 +3,7 @@
|
|||
import sqlalchemy
|
||||
import sqlalchemy.orm.decl_api
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.orderinglist import ordering_list
|
||||
|
|
@ -39,6 +40,32 @@ class Conference(TimeStampedModel):
|
|||
acronym = Column(String)
|
||||
url = Column(String)
|
||||
schedule_xml_url = Column(String)
|
||||
short_name = Column(String, unique=True)
|
||||
|
||||
people_detail = relationship(
|
||||
"ConferencePerson", lazy="dynamic", back_populates="conference"
|
||||
)
|
||||
people = association_proxy("people_detail", "person")
|
||||
|
||||
events = relationship(
|
||||
"Event",
|
||||
order_by="Event.event_date",
|
||||
back_populates="conference",
|
||||
lazy="dynamic",
|
||||
)
|
||||
|
||||
|
||||
class ConferencePerson(Base):
|
||||
__tablename__ = "conference_person"
|
||||
conference_id = Column(Integer, ForeignKey("conference.id"), primary_key=True)
|
||||
person_id = Column(Integer, ForeignKey("person.id"), primary_key=True)
|
||||
named_as = Column(String)
|
||||
bio = Column(String)
|
||||
slug = Column(String)
|
||||
url = Column(String)
|
||||
|
||||
person = relationship("Person", back_populates="conferences_association")
|
||||
conference = relationship("Conference", back_populates="people_detail")
|
||||
|
||||
|
||||
class Event(TimeStampedModel):
|
||||
|
|
@ -48,7 +75,7 @@ class Event(TimeStampedModel):
|
|||
id = Column(Integer, primary_key=True)
|
||||
conference_id = Column(Integer, ForeignKey("conference.id"), nullable=False)
|
||||
event_date = Column(DateTime)
|
||||
day = Column(Integer)
|
||||
# day = Column(Integer)
|
||||
guid = Column(String)
|
||||
start = Column(String)
|
||||
duration = Column(String)
|
||||
|
|
@ -56,22 +83,23 @@ class Event(TimeStampedModel):
|
|||
track = Column(String)
|
||||
slug = Column(String)
|
||||
title = Column(String, nullable=False)
|
||||
abstract = Column(String)
|
||||
description = Column(String)
|
||||
event_type = Column(String)
|
||||
url = Column(String)
|
||||
|
||||
conference = relationship("Conference", backref="events")
|
||||
conference = relationship("Conference", back_populates="events")
|
||||
|
||||
people_association = relationship(
|
||||
people_detail = relationship(
|
||||
"EventPerson",
|
||||
order_by="EventPerson.position",
|
||||
back_populates="event",
|
||||
collection_class=ordering_list("position"),
|
||||
)
|
||||
people = association_proxy(
|
||||
"people_association",
|
||||
"people_detail",
|
||||
"person",
|
||||
creator=lambda person: EventPerson(person=person),
|
||||
creator=lambda i: EventPerson(person=i[0], named_as=i[1]),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -83,9 +111,39 @@ class Person(TimeStampedModel):
|
|||
name = Column(String)
|
||||
wikidata_qid = Column(String)
|
||||
gender = Column(String)
|
||||
wikidata_photo = Column(postgresql.ARRAY(String))
|
||||
|
||||
events_association = relationship("EventPerson", back_populates="person")
|
||||
events = association_proxy("event_association", "event")
|
||||
events_association = relationship(
|
||||
"EventPerson",
|
||||
back_populates="person",
|
||||
lazy="dynamic",
|
||||
)
|
||||
events = association_proxy("events_association", "event")
|
||||
|
||||
conferences_association = relationship("ConferencePerson", back_populates="person")
|
||||
conferences = association_proxy("conference_association", "conference")
|
||||
|
||||
# photos = relationship("PersonPhoto", back_populates="person")
|
||||
|
||||
def events_by_time(self):
|
||||
q = (
|
||||
session.query(Event)
|
||||
.join(EventPerson)
|
||||
.filter(EventPerson.person == self)
|
||||
.order_by(Event.event_date.desc())
|
||||
)
|
||||
|
||||
return q
|
||||
|
||||
|
||||
# class PersonPhoto(TimeStampedModel):
|
||||
# """Person photo."""
|
||||
#
|
||||
# __tablename__ = "person_photo"
|
||||
# person_id = Column(Integer, ForeignKey("person.id"), primary_key=True)
|
||||
# source_filename = Column(String)
|
||||
#
|
||||
# person = relationship("Person", back_populates="photos")
|
||||
|
||||
|
||||
class EventPerson(Base):
|
||||
|
|
@ -95,7 +153,6 @@ class EventPerson(Base):
|
|||
event_id = Column(Integer, ForeignKey("event.id"), primary_key=True)
|
||||
person_id = Column(Integer, ForeignKey("person.id"), primary_key=True)
|
||||
position = Column(Integer, nullable=False)
|
||||
named_as = Column(String)
|
||||
|
||||
person = relationship("Person", back_populates="events_association")
|
||||
event = relationship("Event", back_populates="people_association")
|
||||
event = relationship("Event", back_populates="people_detail")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue