Update app.py
This commit is contained in:
15
app.py
15
app.py
@@ -73,7 +73,11 @@ class Plant(db.Model):
|
||||
size_id = db.Column(db.Integer, db.ForeignKey('size.id'), nullable=True)
|
||||
care_difficulty_id = db.Column(db.Integer, db.ForeignKey('care_difficulty.id'), nullable=True)
|
||||
growth_rate_id = db.Column(db.Integer, db.ForeignKey('growth_rate.id'), nullable=True)
|
||||
section_id = db.Column(db.Integer, db.ForeignKey('section.id'), nullable=True)
|
||||
# Make section_id nullable and handle missing column
|
||||
try:
|
||||
section_id = db.Column(db.Integer, db.ForeignKey('section.id'), nullable=True)
|
||||
except Exception:
|
||||
section_id = None
|
||||
products = db.Column(db.Text, nullable=True) # Will store product IDs as comma-separated values
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
date_added = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||
@@ -86,7 +90,11 @@ class Plant(db.Model):
|
||||
size = db.relationship('Size', backref='plant_size')
|
||||
care_difficulty = db.relationship('CareDifficulty', backref='plant_care_difficulty')
|
||||
growth_rate = db.relationship('GrowthRate', backref='plant_growth_rate')
|
||||
section = db.relationship('Section', backref='plants')
|
||||
# Make section relationship optional
|
||||
try:
|
||||
section = db.relationship('Section', backref='plants')
|
||||
except Exception:
|
||||
section = None
|
||||
|
||||
def __repr__(self):
|
||||
return f"Plant('{self.name}', '{self.date_added}')"
|
||||
@@ -176,6 +184,7 @@ def home():
|
||||
size_id = request.args.get('size')
|
||||
care_difficulty_id = request.args.get('care_difficulty')
|
||||
growth_rate_id = request.args.get('growth_rate')
|
||||
section_id = request.args.get('section')
|
||||
|
||||
query = Plant.query
|
||||
if search:
|
||||
@@ -194,6 +203,8 @@ def home():
|
||||
query = query.filter(Plant.care_difficulty_id == care_difficulty_id)
|
||||
if growth_rate_id:
|
||||
query = query.filter(Plant.growth_rate_id == growth_rate_id)
|
||||
if section_id and hasattr(Plant, 'section_id'):
|
||||
query = query.filter(Plant.section_id == section_id)
|
||||
plants = query.order_by(Plant.date_added.desc()).all()
|
||||
|
||||
climates_dict = {c.id: {'name': c.name, 'icon': c.icon, 'description': c.description} for c in Climate.query.all()}
|
||||
|
||||
Reference in New Issue
Block a user