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