-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
56 lines (44 loc) · 2.31 KB
/
Copy pathmodels.py
File metadata and controls
56 lines (44 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from tortoise import fields, models
from tortoise.contrib.pydantic import pydantic_model_creator
class User(models.Model):
id = fields.IntField(pk=True)
username = fields.CharField(max_length=150, unique=True)
email = fields.CharField(max_length=255, unique=True)
hashed_password = fields.CharField(max_length=255)
is_superuser = fields.BooleanField(default=False)
created_at = fields.DatetimeField(auto_now_add=True)
class Meta:
table = "user"
class Project(models.Model):
id = fields.IntField(pk=True)
user = fields.ForeignKeyField('models.User', related_name='projects')
name = fields.CharField(max_length=255, unique=True)
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
class Meta:
table = "project"
class Category(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=255, unique=True)
class Meta:
table = "category"
class Transaction(models.Model):
id = fields.IntField(pk=True)
user = fields.ForeignKeyField('models.User', related_name='transactions')
amount = fields.DecimalField(max_digits=10, decimal_places=2)
type = fields.CharField(max_length=50) # Either "Income" or "Expense"
project = fields.ForeignKeyField('models.Project', related_name='transactions')
category = fields.ForeignKeyField('models.Category', related_name='transactions')
currency = fields.CharField(max_length=10, default="USD")
description = fields.TextField(null=True)
date = fields.DateField()
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
User_Pydantic = pydantic_model_creator(User, name="User")
UserIn_Pydantic = pydantic_model_creator(User, name="UserIn", exclude_readonly=True)
Category_Pydantic = pydantic_model_creator(Category, name="Category")
CategoryIn_Pydantic = pydantic_model_creator(Category, name="CategoryIn", exclude_readonly=True)
Project_Pydantic = pydantic_model_creator(Project, name="Project")
ProjectIn_Pydantic = pydantic_model_creator(Project, name="ProjectIn", exclude_readonly=True)
Transaction_Pydantic = pydantic_model_creator(Transaction, name="Transaction")
TransactionIn_Pydantic = pydantic_model_creator(Transaction, name="TransactionIn", exclude_readonly=True)