Skip to content

Commit 10e4346

Browse files
committed
Refactor Balance model and add usage examples
1 parent c38e130 commit 10e4346

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

app/Models/balance.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,33 @@ def __repr__(self):
2424
Returns:
2525
str: A string representation of the Balance instance.
2626
"""
27-
return f"<Balance(user_id={self.user_id}, amount={self.amount})>"
27+
return f"<Balance(user_id={self.user_id}, amount={self.amount})>"
28+
29+
# Example usage of the Balance model
30+
31+
# Create a new balance instance for a user with user_id 1
32+
# balance = Balance.create(user_id=1, amount=100.0)
33+
34+
# Get a balance instance by ID
35+
# balance_instance = Balance.get(balance.id)
36+
# print(balance_instance) # Output: <Balance(user_id=1, amount=100.0)>
37+
38+
# Get all balance instances
39+
# all_balances = Balance.all()
40+
# print(all_balances) # Output: [<Balance(user_id=1, amount=100.0)>]
41+
42+
# Update a balance instance by ID
43+
# updated_balance = Balance.update(balance.id, amount=150.0)
44+
# print(updated_balance) # Output: <Balance(user_id=1, amount=150.0)>
45+
46+
# Delete a balance instance by ID
47+
# deleted_balance = Balance.delete(balance.id)
48+
# print(deleted_balance) # Output: <Balance(user_id=1, amount=150.0)>
49+
50+
# Filter balance instances by user_id
51+
# filtered_balances = Balance.filter(user_id=1)
52+
# print(filtered_balances) # Output: [<Balance(user_id=1, amount=150.0)>]
53+
54+
# Check if a balance instance exists by ID
55+
# exists = Balance.exists(balance.id)
56+
# print(exists) # Output: True

0 commit comments

Comments
 (0)