timestamps
This commit is contained in:
parent
3933aa1e9a
commit
bb67552acb
|
|
@ -1,2 +1,9 @@
|
|||
/venv/
|
||||
/instance/
|
||||
/.idea/inspectionProfiles/profiles_settings.xml
|
||||
/.idea/inspectionProfiles/Project_Default.xml
|
||||
/.idea/.gitignore
|
||||
/.idea/misc.xml
|
||||
/.idea/modules.xml
|
||||
/.idea/rifalto.iml
|
||||
/.idea/vcs.xml
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
"""add timestamps
|
||||
|
||||
Revision ID: 78f324ae4f45
|
||||
Revises: 45281a94fd78
|
||||
Create Date: 2023-06-14 17:54:40.318023
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '78f324ae4f45'
|
||||
down_revision = '45281a94fd78'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('purchases', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True))
|
||||
|
||||
with op.batch_alter_table('tickets', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tickets', schema=None) as batch_op:
|
||||
batch_op.drop_column('timestamp')
|
||||
|
||||
with op.batch_alter_table('purchases', schema=None) as batch_op:
|
||||
batch_op.drop_column('timestamp')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -189,7 +189,7 @@ def numbers_screen(purchase_id):
|
|||
@login_required
|
||||
def seller_purchases():
|
||||
seller_id = current_user.id
|
||||
purchases = Purchase.query.filter_by(seller_id=seller_id).order_by(Purchase.id.desc()).all()
|
||||
purchases = Purchase.query.filter_by(seller_id=seller_id).order_by(Purchase.timestamp.desc(), Purchase.id.desc())
|
||||
return render_template('seller_purchases.html', purchases=purchases)
|
||||
|
||||
|
||||
|
|
@ -253,10 +253,3 @@ def change_password(usuario, nova_senha):
|
|||
db.session.commit()
|
||||
|
||||
click.echo(f"Senha para {usuario} foi atualizada.")
|
||||
|
||||
|
||||
@app.cli.command('apply_migrations')
|
||||
@with_appcontext
|
||||
def apply_migrations_command():
|
||||
"""Apply database migrations."""
|
||||
upgrade()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from flask_login import UserMixin
|
|||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy.orm import relationship
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from sqlalchemy import UniqueConstraint
|
||||
from sqlalchemy import UniqueConstraint, func
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ class Purchase(db.Model):
|
|||
total_numbers = db.Column(db.Integer, default=0)
|
||||
numbers_left = db.Column(db.Integer, default=0)
|
||||
remarks = db.Column(db.Text)
|
||||
# timestamp = db.Column(db.DateTime)
|
||||
timestamp = db.Column(db.DateTime, server_default=func.now())
|
||||
|
||||
def generate_id(self):
|
||||
self.id = hashlib.sha256(os.urandom(60)).hexdigest()
|
||||
|
|
@ -59,6 +59,7 @@ class Ticket(db.Model):
|
|||
buyer_name = db.Column(db.String(64))
|
||||
buyer_contact = db.Column(db.String(64))
|
||||
chosen_number = db.Column(db.Integer)
|
||||
timestamp = db.Column(db.DateTime, server_default=func.now())
|
||||
|
||||
raffle = relationship(Raffle)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue