API - fix property name on some relationships
This commit is contained in:
parent
bfea21bc3c
commit
da95706a9d
@ -34,10 +34,14 @@ class User(BaseModel):
|
||||
# does the week start Monday?
|
||||
weekm = db.Column(db.Boolean(50), default=False, nullable=False)
|
||||
workouts = db.relationship(
|
||||
'Workout', lazy=True, backref=db.backref('user', lazy='joined')
|
||||
'Workout',
|
||||
lazy=True,
|
||||
backref=db.backref('user', lazy='joined', single_parent=True),
|
||||
)
|
||||
records = db.relationship(
|
||||
'Record', lazy=True, backref=db.backref('user', lazy='joined')
|
||||
'Record',
|
||||
lazy=True,
|
||||
backref=db.backref('user', lazy='joined', single_parent=True),
|
||||
)
|
||||
language = db.Column(db.String(50), nullable=True)
|
||||
imperial_units = db.Column(db.Boolean, default=False, nullable=False)
|
||||
|
@ -73,10 +73,14 @@ class Sport(BaseModel):
|
||||
is_active = db.Column(db.Boolean, default=True, nullable=False)
|
||||
stopped_speed_threshold = db.Column(db.Float, default=1.0, nullable=False)
|
||||
workouts = db.relationship(
|
||||
'Workout', lazy=True, backref=db.backref('sports', lazy='joined')
|
||||
'Workout',
|
||||
lazy=True,
|
||||
backref=db.backref('sport', lazy='joined', single_parent=True),
|
||||
)
|
||||
records = db.relationship(
|
||||
'Record', lazy=True, backref=db.backref('sports', lazy='joined')
|
||||
'Record',
|
||||
lazy=True,
|
||||
backref=db.backref('sport', lazy='joined', single_parent=True),
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
@ -157,17 +161,17 @@ class Workout(BaseModel):
|
||||
'WorkoutSegment',
|
||||
lazy=True,
|
||||
cascade='all, delete',
|
||||
backref=db.backref('workouts', lazy='joined', single_parent=True),
|
||||
backref=db.backref('workout', lazy='joined', single_parent=True),
|
||||
)
|
||||
records = db.relationship(
|
||||
'Record',
|
||||
lazy=True,
|
||||
cascade='all, delete',
|
||||
backref=db.backref('workouts', lazy='joined', single_parent=True),
|
||||
backref=db.backref('workout', lazy='joined', single_parent=True),
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'<Workout \'{self.sports.label}\' - {self.workout_date}>'
|
||||
return f'<Workout \'{self.sport.label}\' - {self.workout_date}>'
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -450,7 +454,7 @@ class Record(BaseModel):
|
||||
|
||||
def __str__(self) -> str:
|
||||
return (
|
||||
f'<Record {self.sports.label} - '
|
||||
f'<Record {self.sport.label} - '
|
||||
f'{self.record_type} - '
|
||||
f"{self.workout_date.strftime('%Y-%m-%d')}>"
|
||||
)
|
||||
@ -503,7 +507,7 @@ def on_record_delete(
|
||||
) -> None:
|
||||
@listens_for(db.Session, 'after_flush', once=True)
|
||||
def receive_after_flush(session: Session, context: Any) -> None:
|
||||
workout = old_record.workouts
|
||||
workout = old_record.workout
|
||||
new_records = Workout.get_user_workout_records(
|
||||
workout.user_id, workout.sport_id
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user