Please review this at http://codereview.appspot.com/204074/show

Affected files:
  M trytond/model/fields/many2one.py


Index: trytond/model/fields/many2one.py
===================================================================
--- a/trytond/model/fields/many2one.py
+++ b/trytond/model/fields/many2one.py
@@ -26,6 +26,10 @@
         :param datetime_field: The name of the field that contains
the datetime
             value to read the target record.
         '''
+        self.__required = required
+        if ondelete not in ('CASCADE', 'RESTRICT', 'SET NULL'):
+            raise Exception('Bad arguments')
+        self.ondelete = ondelete
         if datetime_field:
             if depends:
                 depends.append(datetime_field)
@@ -40,8 +44,16 @@
         self.model_name = model_name
         self.left = left
         self.right = right
-        if ondelete not in ('CASCADE', 'RESTRICT', 'SET NULL'):
-            raise Exception('Bad arguments')
-        self.ondelete = ondelete
         self.datetime_field = datetime_field
+
+    def __get_required(self):
+        return self.__required
+
+    def __set_required(self, value):
+        self.__required = value
+        if value and self.ondelete == 'SET NULL':
+            self.ondelete = 'RESTRICT'
+
+    required = property(__get_required, __set_required)
+
     __init__.__doc__ += Field.__init__.__doc__



-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpTDYsEJiLiA.pgp
Description: PGP signature

Reply via email to