i understand database slightly better
This commit is contained in:
parent
c8d4d9a660
commit
78da242ce7
24
app.py
24
app.py
|
@ -6,6 +6,7 @@ abort as Abort
|
|||
|
||||
from flask_sqlalchemy import SQLAlchemy as DBM
|
||||
from enum import Enum
|
||||
from datetime import datetime as DT
|
||||
from time import sleep
|
||||
|
||||
# Init
|
||||
|
@ -49,6 +50,8 @@ class LinkType(Enum):
|
|||
class Artist(DB.Model):
|
||||
artist_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
||||
name = DB.Column(DB.String, nullable=False)
|
||||
works = DB.relationship("Work", back_populates="artist")
|
||||
transactions = DB.relationship("Transaction", back_populates="artist")
|
||||
social_twitter = DB.Column(DB.String)
|
||||
social_telegram = DB.Column(DB.String)
|
||||
social_mastodon = DB.Column(DB.String)
|
||||
|
@ -60,9 +63,12 @@ class Artist(DB.Model):
|
|||
class Work(DB.Model):
|
||||
work_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
||||
artist_id = DB.Column(DB.Integer, DB.ForeignKey('artist.artist_id'), nullable=False)
|
||||
artist = DB.relationship("Artist", back_populates="works", uselist=False)
|
||||
state = DB.Column(DB.Enum(WorkState), nullable=False)
|
||||
purchase_type = DB.Column(DB.Enum(TxType),nullable=False)
|
||||
work_desc = DB.Column(DB.String)
|
||||
links = DB.relationship("WorkLink", back_populates="work")
|
||||
transaction = DB.relationship("Transaction", back_populates="work", uselist=False)
|
||||
desc = DB.Column(DB.String)
|
||||
date_proposed = DB.Column(DB.DateTime)
|
||||
date_accepted = DB.Column(DB.DateTime)
|
||||
date_paid = DB.Column(DB.DateTime)
|
||||
|
@ -71,14 +77,17 @@ class Work(DB.Model):
|
|||
class WorkLink(DB.Model):
|
||||
link_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
||||
work_id = DB.Column(DB.Integer, DB.ForeignKey('work.work_id'), nullable=False)
|
||||
work = DB.relationship("Work", back_populates="links", uselist=False)
|
||||
linktype = DB.Column(DB.Enum(LinkType), nullable=False)
|
||||
descr = DB.Column(DB.String, nullable=False)
|
||||
desc = DB.Column(DB.String, nullable=False)
|
||||
uri = DB.Column(DB.String, nullable=False)
|
||||
datetime = DB.Column(DB.DateTime, nullable=False)
|
||||
class Transaction(DB.Model):
|
||||
transaction_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
||||
artist_id = DB.Column(DB.Integer, DB.ForeignKey('artist.artist_id'), nullable=False)
|
||||
artist = DB.relationship("Artist", back_populates="transactions", uselist=False)
|
||||
work_id = DB.Column(DB.Integer, DB.ForeignKey('work.work_id'), nullable=False)
|
||||
work = DB.relationship("Work", back_populates="transaction", uselist=False)
|
||||
processor = DB.Column(DB.Enum(TxProcessor), nullable=False)
|
||||
processor_txid = DB.Column(DB.String, unique=True, nullable=False)
|
||||
currency = DB.Column(DB.Enum(Currency), nullable=False)
|
||||
|
@ -96,11 +105,20 @@ def PopulateTestData():
|
|||
DB.session.add(tArtist)
|
||||
DB.session.commit()
|
||||
tWork=Work(artist_id=tArtist.artist_id,
|
||||
state=WorkState.FINISHED, purchase_type=TxType.NORMAL)
|
||||
state=WorkState.FINISHED, purchase_type=TxType.NORMAL, desc="porno?")
|
||||
tWorkTwo=Work(artist_id=tArtist.artist_id,
|
||||
state=WorkState.INPROGRESS, purchase_type=TxType.YCHAUCTION)
|
||||
DB.session.add_all((tWork, tWorkTwo))
|
||||
DB.session.commit()
|
||||
DB.session.add(WorkLink(work_id=tWork.work_id, linktype=LinkType.DELIVERABLE,
|
||||
uri="rick astley dot com", desc="cool website", datetime=DT.utcnow()))
|
||||
DB.session.add(WorkLink(work_id=tWork.work_id, linktype=LinkType.WIPSKETCH,
|
||||
uri="rick astley dot com", desc="cool website", datetime=DT.utcnow()))
|
||||
DB.session.commit()
|
||||
DB.session.add(Transaction(artist_id=tArtist.artist_id, work_id=tWork.work_id,
|
||||
currency=Currency.GBP, amount=69.42, processor=TxProcessor.PAYPAL,
|
||||
processor_txid="1A7489327fuck", datetime=DT.utcnow()))
|
||||
DB.session.commit()
|
||||
|
||||
#Routes
|
||||
@app.route('/')
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<header>Ideas</header>
|
||||
{% for work in ideas %}
|
||||
<div class="card">
|
||||
<header>{{ work.work_desc }}</header>
|
||||
<header>{{ work.desc|title }}</header>
|
||||
<section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -20,7 +20,7 @@
|
|||
<header>Confirmed/Paid</header>
|
||||
{% for work in cnfpaid %}
|
||||
<div class="card">
|
||||
<header>{{ work.work_desc }}</header>
|
||||
<header>{{ work.desc|title }}</header>
|
||||
<section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -29,7 +29,7 @@
|
|||
<header>In-Progress</header>
|
||||
{% for work in inprog %}
|
||||
<div class="card">
|
||||
<header>{{ work.work_desc }}</header>
|
||||
<header>{{ work.desc|title }}</header>
|
||||
<section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -38,7 +38,7 @@
|
|||
<header>Completed</header>
|
||||
{% for work in done %}
|
||||
<div class="card">
|
||||
<header>{{ work.work_desc }}</header>
|
||||
<header>{{ work.desc|title }}</header>
|
||||
<section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in New Issue