documentation/content/developer/howtos/backend/exercise-constraint-python
Antoine Vandevenne (anv) ebc3e70d0f [APOCALYPSE] Merge all documentations and add a new homemade theme
Co-authored-by: Victor Feyens (vfe) <vfe@odoo.com>
Co-authored-by: Elisabeth Dickinson (edi) <edi@odoo.com>
Co-authored-by: Antoine Vandevenne (anv) <anv@odoo.com>
2021-01-28 19:05:48 +01:00

26 lines
892 B
Plaintext

# HG changeset patch
# Parent 7a7d003fe38426a405ce0657a627a139133ec4dd
# Parent 52f54b46487c8224a5aade4b921be77360ed3eae
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-from odoo import models, fields, api
+from odoo import models, fields, api, exceptions
class Course(models.Model):
_name = 'openacademy.course'
@@ -58,3 +58,9 @@ class Session(models.Model):
'message': "Increase seats or remove excess attendees",
},
}
+
+ @api.constrains('instructor_id', 'attendee_ids')
+ def _check_instructor_not_in_attendees(self):
+ for r in self:
+ if r.instructor_id and r.instructor_id in r.attendee_ids:
+ raise exceptions.ValidationError("A session's instructor can't be an attendee")