mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-09 23:00:16 +00:00
Changed the names of the files to conform the python convection and also added photo_in_entry.py to diminish the cyclic import error in pylint
This commit is contained in:
parent
89e6d0a783
commit
ac29e84833
@@ -0,0 +1,8 @@
|
||||
from pilgrim.application import Application
|
||||
from pilgrim.command import main
|
||||
from pilgrim.database import Database, Base
|
||||
from pilgrim.models.travel_diary import TravelDiary
|
||||
from pilgrim.models.entry import Entry
|
||||
from pilgrim.models.photo import Photo
|
||||
|
||||
__all__ = ["Application", "Database", "TravelDiary", "Entry", "Photo", "main", "Base"]
|
||||
@@ -0,0 +1,9 @@
|
||||
from pilgrim.database import Database
|
||||
|
||||
|
||||
class Application:
|
||||
def __init__(self):
|
||||
self.database = Database()
|
||||
|
||||
def run(self):
|
||||
self.database.create()
|
||||
@@ -0,0 +1,6 @@
|
||||
from pilgrim.application import Application
|
||||
|
||||
|
||||
def main():
|
||||
app = Application()
|
||||
app.run()
|
||||
@@ -0,0 +1,21 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Database:
|
||||
def __init__(self):
|
||||
self.engine = create_engine(
|
||||
"sqlite:///database.db",
|
||||
echo=False,
|
||||
connect_args={"check_same_thread": False},
|
||||
)
|
||||
self.session = sessionmaker(bind=self.engine, autoflush=False, autocommit=False)
|
||||
|
||||
def create(self):
|
||||
Base.metadata.create_all(self.engine)
|
||||
|
||||
def get_db(self):
|
||||
return self.session()
|
||||
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from pilgrim.models.photo_in_entry import photo_entry_association
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class Entry(Base):
|
||||
__tablename__ = "Entry"
|
||||
id = Column(Integer, primary_key=True)
|
||||
title = Column(String)
|
||||
text = Column(String)
|
||||
date = Column(String)
|
||||
photos = relationship(
|
||||
"Photo",
|
||||
secondary=photo_entry_association,
|
||||
back_populates="entries")
|
||||
fk_TravelDiary_id = Column(Integer, ForeignKey("TravelDiary.id"))
|
||||
@@ -0,0 +1,19 @@
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from pilgrim.models.photo_in_entry import photo_entry_association
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class Photo(Base):
|
||||
__tablename__ = "photo"
|
||||
id = Column(Integer, primary_key=True)
|
||||
filepath = Column(String)
|
||||
name = Column(String)
|
||||
addition_date = Column(String)
|
||||
caption = Column(String)
|
||||
entries = relationship(
|
||||
"Entry",
|
||||
secondary=photo_entry_association,
|
||||
back_populates="photos"
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
from sqlalchemy import Table, Column, Integer, ForeignKey
|
||||
|
||||
from ..database import Base
|
||||
|
||||
photo_entry_association = Table('photo_entry_association', Base.metadata,
|
||||
Column('id', Integer, primary_key=True, autoincrement=True),
|
||||
Column('fk_Photo_id', Integer, ForeignKey('photo.id')),
|
||||
Column('fk_Entry_id', Integer, ForeignKey('Entry.id')))
|
||||
@@ -0,0 +1,8 @@
|
||||
from sqlalchemy import Column, String, Integer
|
||||
|
||||
from ..database import Base
|
||||
|
||||
class TravelDiary(Base):
|
||||
__tablename__ = "TravelDiary"
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String)
|
||||
Reference in New Issue
Block a user