feat: set current date automatically when adding a new game to the database
This commit is contained in:
parent
8345ac4e64
commit
58254c4973
@ -3,6 +3,7 @@ from flask_sqlalchemy import SQLAlchemy
|
|||||||
from database import init_db
|
from database import init_db
|
||||||
from models import db, Game
|
from models import db, Game
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'games.db')
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'games.db')
|
||||||
@ -21,7 +22,7 @@ def add_game():
|
|||||||
new_game = Game(
|
new_game = Game(
|
||||||
image=data['image'],
|
image=data['image'],
|
||||||
title=data['title'],
|
title=data['title'],
|
||||||
date=data['date'],
|
date=datetime.now().strftime('%Y-%m-%d'), # Set current date
|
||||||
buyer=data['buyer'],
|
buyer=data['buyer'],
|
||||||
owned=data['owned']
|
owned=data['owned']
|
||||||
)
|
)
|
||||||
|
@ -7,6 +7,6 @@ class Game(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
image = db.Column(db.String(255))
|
image = db.Column(db.String(255))
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
date = db.Column(db.String(10))
|
date = db.Column(db.String(10), nullable=False) # Ensure date is not nullable
|
||||||
buyer = db.Column(db.String(100))
|
buyer = db.Column(db.String(100))
|
||||||
owned = db.Column(db.Boolean, nullable=False)
|
owned = db.Column(db.Boolean, nullable=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user