feat: set current date automatically when adding a new game to the database

This commit is contained in:
Manuel Weiser 2024-09-02 09:49:10 +02:00
parent 8345ac4e64
commit 58254c4973
2 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from flask_sqlalchemy import SQLAlchemy
from database import init_db
from models import db, Game
import os
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'games.db')
@ -21,7 +22,7 @@ def add_game():
new_game = Game(
image=data['image'],
title=data['title'],
date=data['date'],
date=datetime.now().strftime('%Y-%m-%d'), # Set current date
buyer=data['buyer'],
owned=data['owned']
)

View File

@ -7,6 +7,6 @@ class Game(db.Model):
id = db.Column(db.Integer, primary_key=True)
image = db.Column(db.String(255))
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))
owned = db.Column(db.Boolean, nullable=False)