-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
52 lines (38 loc) · 1.45 KB
/
models.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
42
43
44
45
46
47
48
49
50
51
52
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship
from derectoria import database
from derectoria.database import Base
class Author(Base):
__tablename__ = "authors"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
class Book(Base):
__tablename__ = "books"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
author_id = Column(Integer, ForeignKey("authors.id"))
author = relationship("Author")
genre = Column(String)
year = Column(Integer)
pages = Column(Integer)
""" from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from derectoria.database import Base
class Author(Base):
__tablename__ = "authors"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
books = relationship("Book", back_populates="author")
class Book(Base):
__tablename__ = "books"
id = Column(Integer, primary_key=True, index=True)
title = Column(String, index=True)
year = Column(Integer)
pages = Column(Integer)
author_id = Column(Integer, ForeignKey("authors.id"))
author = relationship("Author", back_populates="books")
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key = True, index = True)
name = Column(String, index = True)
password = Column(Integer) """