add method for import data
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from typing import Any, AnyStr, Dict
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -9,6 +10,13 @@ class Article(Base, BaseMixin):
|
||||
title = Column(String, unique=True)
|
||||
article_authors = relationship("ArticleAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.title = import_data['title']
|
||||
|
||||
|
||||
class Author(Base, BaseMixin):
|
||||
__tablename__ = 'author'
|
||||
@@ -17,12 +25,27 @@ class Author(Base, BaseMixin):
|
||||
article_authors = relationship("ArticleAuthor")
|
||||
book_authors = relationship("BookAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
|
||||
|
||||
class BookshelfPublisher(Base, BaseMixin):
|
||||
__tablename__ = 'bookshelf_publisher'
|
||||
name = Column(String, unique=True)
|
||||
books = relationship("Book")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
|
||||
class Book(Base, BaseMixin):
|
||||
__tablename__ = 'book'
|
||||
@@ -33,6 +56,16 @@ class Book(Base, BaseMixin):
|
||||
publisher = relationship('BookshelfPublisher', back_populates="books")
|
||||
book_authors = relationship("BookAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.isbn = import_data['isbn']
|
||||
self.title = import_data['title']
|
||||
self.year = import_data['year']
|
||||
self.publisher_id = import_data['publisher_id']
|
||||
|
||||
|
||||
class ArticleAuthor(Base, BaseMixin):
|
||||
__tablename__ = 'article_author'
|
||||
@@ -41,6 +74,14 @@ class ArticleAuthor(Base, BaseMixin):
|
||||
author_id = Column(String, ForeignKey('author.id'), nullable=False)
|
||||
author = relationship('Author', back_populates="article_authors")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.article_id = import_data['article_id']
|
||||
self.author_id = import_data['author_id']
|
||||
|
||||
|
||||
class BookAuthor(Base, BaseMixin):
|
||||
__tablename__ = 'book_author'
|
||||
@@ -48,3 +89,11 @@ class BookAuthor(Base, BaseMixin):
|
||||
author = relationship('Author', back_populates="book_authors")
|
||||
book_id = Column(String, ForeignKey('book.id'), nullable=False)
|
||||
book = relationship('Book', back_populates="book_authors")
|
||||
|
||||
def import_dict(self, import_data: Dict[AnyStr, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.author_id = import_data['author_id']
|
||||
self.book_id = import_data['book_id']
|
||||
|
||||
Reference in New Issue
Block a user