72 |
73 | 
74 |
--------------------------------------------------------------------------------
/models/models.py:
--------------------------------------------------------------------------------
1 | from odoo import fields, models, api
2 |
3 | # This python module imports:
4 |
5 | # ORM is Object relational mapping which Odoo uses to connect with postgres through psycopg2 lib
6 | # Odoo fields module to implement database columns with a pre-defined sql queries in the ORM module
7 | # Odoo models module to inherit the ORM methods that Odoo uses and create the columns and the behavior
8 | # Odoo api module to access the api annotations of the Odoo ORM methods which each one of them has a purpose,
9 |
10 |
11 | # Odoo fields attributes:
12 |
13 | # required : Setting the field as required for input raises an error if its not filled.
14 | # readonly : Setting the field as readonly which only displays thr field content.
15 | # translate : Adding the ability to translate this field content to other languages. (Amazing Feature)
16 |
17 | # Adding books model to store books data.
18 | class Books (models.Model):
19 |
20 | # Holds the name of the table in database
21 | _name = 'flutter.book'
22 |
23 | # Holds the description of the table in database
24 | _description = 'Model for storing books and do CRUD operations.'
25 |
26 | # Sorts the categories descending order with the time of creation.
27 | _order = "create_date desc"
28 |
29 | # Adding a filed (column) for the name of the book. Char is varchar or string with a small length.
30 | name = fields.Char(required=True,translate=True)
31 |
32 | # Adding a filed (column) for the activeness of the book which stores true or false to determine
33 | # if the book is still in stock for sale..
34 | active = fields.Boolean(default=True)
35 |
36 | # Adding a filed (column) for the number of the book. Integer is a field for numbers.
37 | number = fields.Integer()
38 |
39 | # Adding a filed (column) for the description of the book which has more string length than char.
40 | description = fields.Text(required=True)
41 |
42 | # Adding a filed (column) for the image of the book which stores binary data for any file format.
43 | image = fields.Binary()
44 |
45 | # Adding a filed (column) for the status of the book which stores a string of the current state.
46 | state = fields.Selection([
47 | ('draft','Draft'),
48 | ('waiting','Waiting approval'),
49 | ('reviewed','Reviewed'),
50 | ('published','Published'),
51 | ],default='draft',readonly=True)
52 |
53 | # Adding a filed (column) for the publish date of the book which stores string containing a
54 | # date format.
55 | publish_date = fields.Date()
56 |
57 | # Adding a filed (column) for the language of the book which stores string containing the key
58 | # of the selected option.
59 | language = fields.Selection([
60 | ('ar','Arabic'),
61 | ('en','english')
62 | ],default='en')
63 |
64 | # Adding a filed (column) for the isbn of the book. Char is varchar or string with a
65 | # small length. You can use char to store numbers sometime which is more advanced.
66 | isbn = fields.Char("International Standard Book Number")
67 |
68 | # Adding a filed (column) for the price cost of the book which stores real number.
69 | price = fields.Float(required=True)
70 |
71 | # Adding a filed (column) for the relation of the author with the book which stores
72 | # the author id who wrote the book.
73 | author = fields.Many2one("flutter.author",required=True)
74 |
75 | # Adding a filed (column) for the relation of the publisher with the book which stores
76 | # the publisher id who published the book of the author.
77 | publisher = fields.Many2one("flutter.publisher",required=True)
78 |
79 | # Adding a filed (column) for the relation of the categories with the books which stores
80 | # the categories ids which the admin selected. Note: postgres stores then as ids but odoo
81 | # display them as lists and when you click on them you can choose what categories you want
82 | # for this book.
83 | categories = fields.Many2many("flutter.category")
84 |
85 | # Adding author model for book authors.
86 | class Author (models.Model):
87 |
88 | # Holds the name of the table in database
89 | _name = 'flutter.author'
90 |
91 | # Holds the description of the table in database
92 | _description = 'Model for storing authors of books and do CRUD operations.'
93 |
94 | # Sorts the authors descending order with the time of registration.
95 | _order = "create_date desc"
96 |
97 | # Adding a filed (column) for the name of the author. Char is varchar or string with a
98 | # small length.
99 | name = fields.Char(required=True,translate=True)
100 |
101 | # Adding a filed (column) for the image of the author which stores binary data for any
102 | # file format.
103 | image = fields.Binary()
104 |
105 | # Adding a filed (column) for the reverse relation of the publisher with the book which
106 | # stores all the books ids that the publisher had published. Note: postgres stores ids
107 | # but odoo displays them as a list of books records in his views which is nice.
108 | books = fields.One2many("flutter.book","author")
109 |
110 | # Adding a publisher model to store publishers info
111 | class Publisher (models.Model):
112 |
113 | # Holds the name of the table in database
114 | _name = 'flutter.publisher'
115 |
116 | # Holds the description of the table in database
117 | _description = 'Model for storing publishers of books and do CRUD operations.'
118 |
119 | # Sorts the publishers descending order with the time of registration.
120 | _order = "create_date desc"
121 |
122 | # Adding a filed (column) for the name of the publisher. Char is varchar or string with
123 | # a small length.
124 | name = fields.Char(required=True,translate=True)
125 |
126 | # Adding a filed (column) for the image of the publisher which stores binary data for any
127 | # file format.
128 | image = fields.Binary()
129 |
130 | # Adding a filed (column) for the reverse relation of the publisher with the book which
131 | # stores all the books ids that the publisher had published. Note: postgres stores ids but
132 | # odoo displays them as a list of books records in his views which is nice.
133 | books = fields.One2many("flutter.book", "publisher")
134 |
135 | # Adding a category model to store multiple categories of the published books.
136 | class Category (models.Model):
137 |
138 | # Holds the name of the table in database
139 | _name = 'flutter.category'
140 |
141 | # Holds the description of the table in database
142 | _description = 'Model for storing categories of the books and do CRUD operations.'
143 |
144 | # Sorts the categories descending order with the time of creation.
145 | _order = "create_date desc"
146 |
147 | # Adding a filed (column) for the name of the publisher. Char is varchar or string with
148 | # a small length.
149 | name = fields.Char(required=True,translate=True)
150 |
151 | # Adding a filed (column) for the reverse relation of the categories with the books which
152 | # stores the books ids which the admin selected for the book. Note: postgres stores then
153 | # as ids but odoo display them as lists and when you click on them you can choose what
154 | # books you want for this category.
155 | books = fields.Many2many("flutter.book")
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
25 |
26 |
27 |