i understand database slightly better

This commit is contained in:
root 2020-10-05 19:20:44 +01:00
parent c8d4d9a660
commit 78da242ce7
3 changed files with 26 additions and 8 deletions

BIN
app.db

Binary file not shown.

24
app.py
View File

@ -6,6 +6,7 @@ abort as Abort
from flask_sqlalchemy import SQLAlchemy as DBM from flask_sqlalchemy import SQLAlchemy as DBM
from enum import Enum from enum import Enum
from datetime import datetime as DT
from time import sleep from time import sleep
# Init # Init
@ -49,6 +50,8 @@ class LinkType(Enum):
class Artist(DB.Model): class Artist(DB.Model):
artist_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True) artist_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
name = DB.Column(DB.String, nullable=False) 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_twitter = DB.Column(DB.String)
social_telegram = DB.Column(DB.String) social_telegram = DB.Column(DB.String)
social_mastodon = DB.Column(DB.String) social_mastodon = DB.Column(DB.String)
@ -60,9 +63,12 @@ class Artist(DB.Model):
class Work(DB.Model): class Work(DB.Model):
work_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True) 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_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) state = DB.Column(DB.Enum(WorkState), nullable=False)
purchase_type = DB.Column(DB.Enum(TxType),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_proposed = DB.Column(DB.DateTime)
date_accepted = DB.Column(DB.DateTime) date_accepted = DB.Column(DB.DateTime)
date_paid = DB.Column(DB.DateTime) date_paid = DB.Column(DB.DateTime)
@ -71,14 +77,17 @@ class Work(DB.Model):
class WorkLink(DB.Model): class WorkLink(DB.Model):
link_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True) 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_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) 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) uri = DB.Column(DB.String, nullable=False)
datetime = DB.Column(DB.DateTime, nullable=False) datetime = DB.Column(DB.DateTime, nullable=False)
class Transaction(DB.Model): class Transaction(DB.Model):
transaction_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True) 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_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_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 = DB.Column(DB.Enum(TxProcessor), nullable=False)
processor_txid = DB.Column(DB.String, unique=True, nullable=False) processor_txid = DB.Column(DB.String, unique=True, nullable=False)
currency = DB.Column(DB.Enum(Currency), nullable=False) currency = DB.Column(DB.Enum(Currency), nullable=False)
@ -96,11 +105,20 @@ def PopulateTestData():
DB.session.add(tArtist) DB.session.add(tArtist)
DB.session.commit() DB.session.commit()
tWork=Work(artist_id=tArtist.artist_id, 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, tWorkTwo=Work(artist_id=tArtist.artist_id,
state=WorkState.INPROGRESS, purchase_type=TxType.YCHAUCTION) state=WorkState.INPROGRESS, purchase_type=TxType.YCHAUCTION)
DB.session.add_all((tWork, tWorkTwo)) DB.session.add_all((tWork, tWorkTwo))
DB.session.commit() 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 #Routes
@app.route('/') @app.route('/')

View File

@ -11,7 +11,7 @@
<header>Ideas</header> <header>Ideas</header>
{% for work in ideas %} {% for work in ideas %}
<div class="card"> <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> <section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
</div> </div>
{% endfor %} {% endfor %}
@ -20,7 +20,7 @@
<header>Confirmed/Paid</header> <header>Confirmed/Paid</header>
{% for work in cnfpaid %} {% for work in cnfpaid %}
<div class="card"> <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> <section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
</div> </div>
{% endfor %} {% endfor %}
@ -29,7 +29,7 @@
<header>In-Progress</header> <header>In-Progress</header>
{% for work in inprog %} {% for work in inprog %}
<div class="card"> <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> <section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
</div> </div>
{% endfor %} {% endfor %}
@ -38,7 +38,7 @@
<header>Completed</header> <header>Completed</header>
{% for work in done %} {% for work in done %}
<div class="card"> <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> <section>status {{ work.state.name|title }} and artist {{ work.artist.name }}</section>
</div> </div>
{% endfor %} {% endfor %}