[IMP] doc/howtos/backend: improve exercises on relational fields
This commit is contained in:
parent
856daf8df9
commit
570ea406c8
|
@ -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
|
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
|
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
|
.. 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::
|
.. patch::
|
||||||
|
|
||||||
|
@ -530,7 +531,7 @@ Relational field types are:
|
||||||
accessing it results in a (possibly empty) set of records::
|
accessing it results in a (possibly empty) set of records::
|
||||||
|
|
||||||
for other in foo.other_ids:
|
for other in foo.other_ids:
|
||||||
print foo.name
|
print other.name
|
||||||
|
|
||||||
.. danger::
|
.. danger::
|
||||||
|
|
||||||
|
@ -544,7 +545,7 @@ Relational field types are:
|
||||||
records, accessing it also results in a possibly empty set of records::
|
records, accessing it also results in a possibly empty set of records::
|
||||||
|
|
||||||
for other in foo.other_ids:
|
for other in foo.other_ids:
|
||||||
print foo.name
|
print other.name
|
||||||
|
|
||||||
.. exercise:: Many2one relations
|
.. exercise:: Many2one relations
|
||||||
|
|
||||||
|
@ -557,12 +558,12 @@ Relational field types are:
|
||||||
built-in model ``res.partner``.
|
built-in model ``res.partner``.
|
||||||
- A session is related to a *course*; the value of that field is a record
|
- A session is related to a *course*; the value of that field is a record
|
||||||
of the model ``openacademy.course`` and is required.
|
of the model ``openacademy.course`` and is required.
|
||||||
|
- Adapt the views.
|
||||||
|
|
||||||
.. only:: solutions
|
.. only:: solutions
|
||||||
|
|
||||||
#. Add the relevant ``Many2one`` fields to the models, and
|
#. Add the relevant ``Many2one`` fields to the models, and
|
||||||
#. add access to the session object in
|
#. add them in the views.
|
||||||
``openacademy/view/openacademy.xml``.
|
|
||||||
|
|
||||||
.. patch::
|
.. patch::
|
||||||
|
|
||||||
|
@ -573,7 +574,8 @@ Relational field types are:
|
||||||
|
|
||||||
.. only:: solutions
|
.. only:: solutions
|
||||||
|
|
||||||
Modify the ``Course`` class as follows:
|
#. Modify the ``Course`` class, and
|
||||||
|
#. add the field in the course form view.
|
||||||
|
|
||||||
.. patch::
|
.. patch::
|
||||||
|
|
||||||
|
@ -582,32 +584,12 @@ Relational field types are:
|
||||||
Using the relational field many2many, modify the *Session* model to relate
|
Using the relational field many2many, modify the *Session* model to relate
|
||||||
every session to a set of *attendees*. Attendees will be represented by
|
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``.
|
partner records, so we will relate to the built-in model ``res.partner``.
|
||||||
|
Adapt the views accordingly.
|
||||||
|
|
||||||
.. only:: solutions
|
.. only:: solutions
|
||||||
|
|
||||||
Modify the ``Session`` class as follows:
|
#. Modify the ``Session`` class, and
|
||||||
|
#. add the field in the form view.
|
||||||
.. 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
|
|
||||||
|
|
||||||
.. patch::
|
.. patch::
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,22 @@
|
||||||
Index: addons/openacademy/models.py
|
Index: addons/openacademy/models.py
|
||||||
===================================================================
|
===================================================================
|
||||||
--- addons.orig/openacademy/models.py 2014-08-26 17:25:59.483783379 +0200
|
--- addons.orig/openacademy/models.py 2014-08-27 10:34:08.531934946 +0200
|
||||||
+++ addons/openacademy/models.py 2014-08-26 17:25:59.479783379 +0200
|
+++ addons/openacademy/models.py 2014-08-27 10:34:08.527934946 +0200
|
||||||
@@ -25,3 +25,4 @@
|
@@ -25,3 +25,4 @@
|
||||||
instructor_id = fields.Many2one('res.partner', string="Instructor")
|
instructor_id = fields.Many2one('res.partner', string="Instructor")
|
||||||
course_id = fields.Many2one('openacademy.course',
|
course_id = fields.Many2one('openacademy.course',
|
||||||
ondelete='cascade', string="Course", required=True)
|
ondelete='cascade', string="Course", required=True)
|
||||||
+ attendee_ids = fields.Many2many('res.partner', string="Attendees")
|
+ 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 @@
|
||||||
|
<field name="seats"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
+ <label for="attendee_ids"/>
|
||||||
|
+ <field name="attendee_ids"/>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
Index: addons/openacademy/models.py
|
Index: addons/openacademy/models.py
|
||||||
===================================================================
|
===================================================================
|
||||||
--- addons.orig/openacademy/models.py 2014-08-26 17:25:57.515783409 +0200
|
--- addons.orig/openacademy/models.py 2014-08-27 10:37:10.135932250 +0200
|
||||||
+++ addons/openacademy/models.py 2014-08-26 17:25:57.511783409 +0200
|
+++ addons/openacademy/models.py 2014-08-27 10:37:10.131932250 +0200
|
||||||
@@ -8,6 +8,9 @@
|
@@ -8,6 +8,9 @@
|
||||||
name = fields.Char(string="Title", required=True)
|
name = fields.Char(string="Title", required=True)
|
||||||
description = fields.Text()
|
description = fields.Text()
|
||||||
|
@ -25,22 +25,71 @@ Index: addons/openacademy/models.py
|
||||||
+ ondelete='cascade', string="Course", required=True)
|
+ ondelete='cascade', string="Course", required=True)
|
||||||
Index: addons/openacademy/views/openacademy.xml
|
Index: addons/openacademy/views/openacademy.xml
|
||||||
===================================================================
|
===================================================================
|
||||||
--- addons.orig/openacademy/views/openacademy.xml 2014-08-26 17:25:57.515783409 +0200
|
--- addons.orig/openacademy/views/openacademy.xml 2014-08-27 10:37:10.135932250 +0200
|
||||||
+++ addons/openacademy/views/openacademy.xml 2014-08-26 17:25:57.511783409 +0200
|
+++ addons/openacademy/views/openacademy.xml 2014-08-27 10:37:10.131932250 +0200
|
||||||
@@ -64,5 +64,16 @@
|
@@ -9,6 +9,7 @@
|
||||||
<!-- Full id location:
|
<sheet>
|
||||||
action="openacademy.course_list_action"
|
<group>
|
||||||
It is not required when it is the same module -->
|
<field name="name"/>
|
||||||
+
|
+ <field name="responsible_id"/>
|
||||||
+ <record model="ir.actions.act_window" id="session_list_action">
|
</group>
|
||||||
+ <field name="name">Sessions</field>
|
<notebook>
|
||||||
+ <field name="res_model">openacademy.session</field>
|
<page string="Description">
|
||||||
+ <field name="view_type">form</field>
|
@@ -34,6 +35,18 @@
|
||||||
+ <field name="view_mode">tree,form</field>
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
+ <!-- override the automatically generated list view for courses -->
|
||||||
|
+ <record model="ir.ui.view" id="course_tree_view">
|
||||||
|
+ <field name="name">course.tree</field>
|
||||||
|
+ <field name="model">openacademy.course</field>
|
||||||
|
+ <field name="arch" type="xml">
|
||||||
|
+ <tree string="Course Tree">
|
||||||
|
+ <field name="name"/>
|
||||||
|
+ <field name="responsible_id"/>
|
||||||
|
+ </tree>
|
||||||
|
+ </field>
|
||||||
+ </record>
|
+ </record>
|
||||||
+
|
+
|
||||||
+ <menuitem id="session_menu" name="Sessions"
|
<!-- window action -->
|
||||||
+ parent="openacademy_menu"
|
<!--
|
||||||
+ action="session_list_action"/>
|
The following tag is an action definition for a "window action",
|
||||||
</data>
|
@@ -73,16 +86,34 @@
|
||||||
</openerp>
|
<form string="Session Form">
|
||||||
|
<sheet>
|
||||||
|
<group>
|
||||||
|
- <field name="name"/>
|
||||||
|
- <field name="start_date"/>
|
||||||
|
- <field name="duration"/>
|
||||||
|
- <field name="seats"/>
|
||||||
|
+ <group string="General">
|
||||||
|
+ <field name="course_id"/>
|
||||||
|
+ <field name="name"/>
|
||||||
|
+ <field name="instructor_id"/>
|
||||||
|
+ </group>
|
||||||
|
+ <group string="Schedule">
|
||||||
|
+ <field name="start_date"/>
|
||||||
|
+ <field name="duration"/>
|
||||||
|
+ <field name="seats"/>
|
||||||
|
+ </group>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
+ <!-- session tree/list view -->
|
||||||
|
+ <record model="ir.ui.view" id="session_tree_view">
|
||||||
|
+ <field name="name">session.tree</field>
|
||||||
|
+ <field name="model">openacademy.session</field>
|
||||||
|
+ <field name="arch" type="xml">
|
||||||
|
+ <tree string="Session Tree">
|
||||||
|
+ <field name="name"/>
|
||||||
|
+ <field name="course_id"/>
|
||||||
|
+ </tree>
|
||||||
|
+ </field>
|
||||||
|
+ </record>
|
||||||
|
+
|
||||||
|
<record model="ir.actions.act_window" id="session_list_action">
|
||||||
|
<field name="name">Sessions</field>
|
||||||
|
<field name="res_model">openacademy.session</field>
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
Index: addons/openacademy/models.py
|
Index: addons/openacademy/models.py
|
||||||
===================================================================
|
===================================================================
|
||||||
--- addons.orig/openacademy/models.py 2014-08-26 17:25:58.455783395 +0200
|
--- addons.orig/openacademy/models.py 2014-08-27 10:37:24.591932036 +0200
|
||||||
+++ addons/openacademy/models.py 2014-08-26 17:25:58.447783395 +0200
|
+++ addons/openacademy/models.py 2014-08-27 10:37:24.583932036 +0200
|
||||||
@@ -10,6 +10,8 @@
|
@@ -10,6 +10,8 @@
|
||||||
|
|
||||||
responsible_id = fields.Many2one('res.users',
|
responsible_id = fields.Many2one('res.users',
|
||||||
|
@ -14,3 +14,23 @@ Index: addons/openacademy/models.py
|
||||||
|
|
||||||
|
|
||||||
class Session(models.Model):
|
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 @@
|
||||||
|
<page string="Description">
|
||||||
|
<field name="description"/>
|
||||||
|
</page>
|
||||||
|
- <page string="About">
|
||||||
|
- This is an example of notebooks
|
||||||
|
+ <page string="Sessions">
|
||||||
|
+ <field name="session_ids">
|
||||||
|
+ <tree string="Registered sessions">
|
||||||
|
+ <field name="name"/>
|
||||||
|
+ <field name="instructor_id"/>
|
||||||
|
+ </tree>
|
||||||
|
+ </field>
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
</sheet>
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
# Parent 22f8d180a7f9ad209d7e98cf7d1bd0fee1f05350
|
# Parent 22f8d180a7f9ad209d7e98cf7d1bd0fee1f05350
|
||||||
Index: addons/openacademy/models.py
|
Index: addons/openacademy/models.py
|
||||||
===================================================================
|
===================================================================
|
||||||
--- addons.orig/openacademy/models.py 2014-08-26 17:25:56.603783422 +0200
|
--- addons.orig/openacademy/models.py 2014-08-27 10:35:29.179933749 +0200
|
||||||
+++ addons/openacademy/models.py 2014-08-26 17:25:56.595783422 +0200
|
+++ addons/openacademy/models.py 2014-08-27 10:35:56.000000000 +0200
|
||||||
@@ -7,3 +7,12 @@
|
@@ -7,3 +7,12 @@
|
||||||
|
|
||||||
name = fields.Char(string="Title", required=True)
|
name = fields.Char(string="Title", required=True)
|
||||||
|
@ -17,3 +17,42 @@ Index: addons/openacademy/models.py
|
||||||
+ start_date = fields.Date()
|
+ start_date = fields.Date()
|
||||||
+ duration = fields.Float(digits=(6, 2), help="Duration in days")
|
+ duration = fields.Float(digits=(6, 2), help="Duration in days")
|
||||||
+ seats = fields.Integer(string="Number of seats")
|
+ 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 @@
|
||||||
|
<!-- Full id location:
|
||||||
|
action="openacademy.course_list_action"
|
||||||
|
It is not required when it is the same module -->
|
||||||
|
+
|
||||||
|
+ <!-- session form view -->
|
||||||
|
+ <record model="ir.ui.view" id="session_form_view">
|
||||||
|
+ <field name="name">session.form</field>
|
||||||
|
+ <field name="model">openacademy.session</field>
|
||||||
|
+ <field name="arch" type="xml">
|
||||||
|
+ <form string="Session Form">
|
||||||
|
+ <sheet>
|
||||||
|
+ <group>
|
||||||
|
+ <field name="name"/>
|
||||||
|
+ <field name="start_date"/>
|
||||||
|
+ <field name="duration"/>
|
||||||
|
+ <field name="seats"/>
|
||||||
|
+ </group>
|
||||||
|
+ </sheet>
|
||||||
|
+ </form>
|
||||||
|
+ </field>
|
||||||
|
+ </record>
|
||||||
|
+
|
||||||
|
+ <record model="ir.actions.act_window" id="session_list_action">
|
||||||
|
+ <field name="name">Sessions</field>
|
||||||
|
+ <field name="res_model">openacademy.session</field>
|
||||||
|
+ <field name="view_type">form</field>
|
||||||
|
+ <field name="view_mode">tree,form</field>
|
||||||
|
+ </record>
|
||||||
|
+
|
||||||
|
+ <menuitem id="session_menu" name="Sessions"
|
||||||
|
+ parent="openacademy_menu"
|
||||||
|
+ action="session_list_action"/>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
|
|
|
@ -9,7 +9,6 @@ exercise-session
|
||||||
exercise-many2one
|
exercise-many2one
|
||||||
exercise-one2many
|
exercise-one2many
|
||||||
exercise-many2many
|
exercise-many2many
|
||||||
exercise-o2m-views
|
|
||||||
exercise-model-inheritance
|
exercise-model-inheritance
|
||||||
exercise-domain-basic
|
exercise-domain-basic
|
||||||
exercise-domain-advanced
|
exercise-domain-advanced
|
||||||
|
|
Loading…
Reference in New Issue