-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
41 lines (30 loc) · 950 Bytes
/
example.py
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
from datetime import datetime
from weekorm import model
from weekorm.db import DataBase
db = DataBase('example.sqlite')
class User(model.Model):
name = model.CharField(max_length=20)
email = model.CharField(max_length=40, unique=True)
birthday = model.DateTimeField()
is_admin = model.BooleanField(default=False)
def __str__(self):
return self.name
class Staff(model.Model):
user = model.ForeignKey(User)
position = model.CharField(max_length=40)
def __str__(self):
return f'{self.position} - {self.user.name}'
user = User(
name='Mik',
email='mik@gmail.com',
birthday=datetime(year=2000, month=1, day=1)
)
staff = Staff(user=user, position='Tester')
if User.query().filter(email=user.email).first():
print('This user is already in the database')
else:
print('Create user ans stuff')
print(f'user: {user}')
print(f'staff {staff}')
user.save()
staff.save()