From 570ea406c8fda57bf9bb8cfc7256adb05b6429e0 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 27 Aug 2014 10:45:56 +0200 Subject: [PATCH] [IMP] doc/howtos/backend: improve exercises on relational fields --- doc/howtos/backend.rst | 42 ++++--------- doc/howtos/backend/exercise-many2many | 17 +++++- doc/howtos/backend/exercise-many2one | 87 +++++++++++++++++++++------ doc/howtos/backend/exercise-one2many | 24 +++++++- doc/howtos/backend/exercise-session | 43 ++++++++++++- doc/howtos/backend/series | 1 - 6 files changed, 158 insertions(+), 56 deletions(-) diff --git a/doc/howtos/backend.rst b/doc/howtos/backend.rst index de96f53ba58..7af76db6354 100644 --- a/doc/howtos/backend.rst +++ b/doc/howtos/backend.rst @@ -496,11 +496,12 @@ client data; it is also related to its sale order line records. Create a model for *sessions*. A session has a name, a start date, a duration and a number of seats. Add an action and a menu item to display - them. + them. Make the new model visible via a menu item. .. only:: solutions - Create the class *Session* in ``openacademy/models.py``. + #. Create the class *Session* in ``openacademy/models.py``. + #. Add access to the session object in ``openacademy/view/openacademy.xml``. .. patch:: @@ -530,7 +531,7 @@ Relational field types are: accessing it results in a (possibly empty) set of records:: for other in foo.other_ids: - print foo.name + print other.name .. danger:: @@ -544,7 +545,7 @@ Relational field types are: records, accessing it also results in a possibly empty set of records:: for other in foo.other_ids: - print foo.name + print other.name .. exercise:: Many2one relations @@ -557,12 +558,12 @@ Relational field types are: built-in model ``res.partner``. - A session is related to a *course*; the value of that field is a record of the model ``openacademy.course`` and is required. + - Adapt the views. .. only:: solutions #. Add the relevant ``Many2one`` fields to the models, and - #. add access to the session object in - ``openacademy/view/openacademy.xml``. + #. add them in the views. .. patch:: @@ -573,7 +574,8 @@ Relational field types are: .. only:: solutions - Modify the ``Course`` class as follows: + #. Modify the ``Course`` class, and + #. add the field in the course form view. .. patch:: @@ -582,32 +584,12 @@ Relational field types are: Using the relational field many2many, modify the *Session* model to relate every session to a set of *attendees*. Attendees will be represented by partner records, so we will relate to the built-in model ``res.partner``. + Adapt the views accordingly. .. only:: solutions - Modify the ``Session`` class as follows: - - .. patch:: - -.. exercise:: Views modification - - For the *Course* model, - - * the name and instructor for the course should be displayed in the tree - view - * the form view should display the course name and responsible at - the top, followed by the course description in a tab and the course - sessions in a second tab - - For the *Session* model, - - * the name of the session and the session course should be displayed in - the tree view - * the form view should display all the session's fields - - Try to lay out the form views so that they're clear and readable. - - .. only:: solutions + #. Modify the ``Session`` class, and + #. add the field in the form view. .. patch:: diff --git a/doc/howtos/backend/exercise-many2many b/doc/howtos/backend/exercise-many2many index e8242a46a5a..b463bd612d3 100644 --- a/doc/howtos/backend/exercise-many2many +++ b/doc/howtos/backend/exercise-many2many @@ -1,9 +1,22 @@ Index: addons/openacademy/models.py =================================================================== ---- addons.orig/openacademy/models.py 2014-08-26 17:25:59.483783379 +0200 -+++ addons/openacademy/models.py 2014-08-26 17:25:59.479783379 +0200 +--- addons.orig/openacademy/models.py 2014-08-27 10:34:08.531934946 +0200 ++++ addons/openacademy/models.py 2014-08-27 10:34:08.527934946 +0200 @@ -25,3 +25,4 @@ instructor_id = fields.Many2one('res.partner', string="Instructor") course_id = fields.Many2one('openacademy.course', ondelete='cascade', string="Course", required=True) + attendee_ids = fields.Many2many('res.partner', string="Attendees") +Index: addons/openacademy/views/openacademy.xml +=================================================================== +--- addons.orig/openacademy/views/openacademy.xml 2014-08-27 10:34:08.531934946 +0200 ++++ addons/openacademy/views/openacademy.xml 2014-08-27 10:34:08.527934946 +0200 +@@ -102,6 +102,8 @@ + + + ++ + + ++ ++ ++ course.tree ++ openacademy.course ++ ++ ++ ++ ++ ++ + + -+ - - + + ++ ++ session.tree ++ openacademy.session ++ ++ ++ ++ ++ ++ ++ ++ + + Sessions + openacademy.session diff --git a/doc/howtos/backend/exercise-one2many b/doc/howtos/backend/exercise-one2many index 6d5f18e6e7c..b06733210a1 100644 --- a/doc/howtos/backend/exercise-one2many +++ b/doc/howtos/backend/exercise-one2many @@ -3,8 +3,8 @@ Index: addons/openacademy/models.py =================================================================== ---- addons.orig/openacademy/models.py 2014-08-26 17:25:58.455783395 +0200 -+++ addons/openacademy/models.py 2014-08-26 17:25:58.447783395 +0200 +--- addons.orig/openacademy/models.py 2014-08-27 10:37:24.591932036 +0200 ++++ addons/openacademy/models.py 2014-08-27 10:37:24.583932036 +0200 @@ -10,6 +10,8 @@ responsible_id = fields.Many2one('res.users', @@ -14,3 +14,23 @@ Index: addons/openacademy/models.py class Session(models.Model): +Index: addons/openacademy/views/openacademy.xml +=================================================================== +--- addons.orig/openacademy/views/openacademy.xml 2014-08-27 10:37:24.591932036 +0200 ++++ addons/openacademy/views/openacademy.xml 2014-08-27 10:37:24.583932036 +0200 +@@ -15,8 +15,13 @@ + + + +- +- This is an example of notebooks ++ ++ ++ ++ ++ ++ ++ + + + diff --git a/doc/howtos/backend/exercise-session b/doc/howtos/backend/exercise-session index ec3c845b15e..993ee0a7dd6 100644 --- a/doc/howtos/backend/exercise-session +++ b/doc/howtos/backend/exercise-session @@ -2,8 +2,8 @@ # Parent 22f8d180a7f9ad209d7e98cf7d1bd0fee1f05350 Index: addons/openacademy/models.py =================================================================== ---- addons.orig/openacademy/models.py 2014-08-26 17:25:56.603783422 +0200 -+++ addons/openacademy/models.py 2014-08-26 17:25:56.595783422 +0200 +--- addons.orig/openacademy/models.py 2014-08-27 10:35:29.179933749 +0200 ++++ addons/openacademy/models.py 2014-08-27 10:35:56.000000000 +0200 @@ -7,3 +7,12 @@ name = fields.Char(string="Title", required=True) @@ -17,3 +17,42 @@ Index: addons/openacademy/models.py + start_date = fields.Date() + duration = fields.Float(digits=(6, 2), help="Duration in days") + seats = fields.Integer(string="Number of seats") +Index: addons/openacademy/views/openacademy.xml +=================================================================== +--- addons.orig/openacademy/views/openacademy.xml 2014-08-27 10:35:29.179933749 +0200 ++++ addons/openacademy/views/openacademy.xml 2014-08-27 10:36:54.643932480 +0200 +@@ -64,5 +64,34 @@ + ++ ++ ++ ++ session.form ++ openacademy.session ++ ++
++ ++ ++ ++ ++ ++ ++ ++ ++
++
++
++ ++ ++ Sessions ++ openacademy.session ++ form ++ tree,form ++ ++ ++ + + diff --git a/doc/howtos/backend/series b/doc/howtos/backend/series index 0206331ebaa..c21ba1502bd 100644 --- a/doc/howtos/backend/series +++ b/doc/howtos/backend/series @@ -9,7 +9,6 @@ exercise-session exercise-many2one exercise-one2many exercise-many2many -exercise-o2m-views exercise-model-inheritance exercise-domain-basic exercise-domain-advanced