Browse Source

[#11] Ajout d'une méthode dans les fieldtypes pour retourner les arguments sqlalchemy

Roland Haroutiounian 9 years ago
parent
commit
46a60bdb89
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      EditorialModel/fieldtypes.py

+ 12
- 0
EditorialModel/fieldtypes.py View File

2
 
2
 
3
 from EditorialModel.components import EmComponent, EmComponentNotExistError
3
 from EditorialModel.components import EmComponent, EmComponentNotExistError
4
 from Lodel.utils.mlstring import MlString
4
 from Lodel.utils.mlstring import MlString
5
+from sqlalchemy import Column, INTEGER, BOOLEAN
5
 
6
 
6
 def get_field_type(name):
7
 def get_field_type(name):
7
     class_name = 'EmField_' + name
8
     class_name = 'EmField_' + name
34
     def sql_column(self):
35
     def sql_column(self):
35
         return "int(11) NOT NULL"
36
         return "int(11) NOT NULL"
36
 
37
 
38
+    def sqlalchemy_args(self):
39
+        # TODO Ajouter la prise en charge de la taille max
40
+        return {'type_': INTEGER, 'nullable': False}
37
 
41
 
38
 class EmField_boolean(EmFieldType):
42
 class EmField_boolean(EmFieldType):
39
 
43
 
55
     def sql_column(self):
59
     def sql_column(self):
56
         return "tinyint(1) DEFAULT NULL"
60
         return "tinyint(1) DEFAULT NULL"
57
 
61
 
62
+    def sqlalchemy_args(self):
63
+        return {'type_': BOOLEAN, 'nullable': True, 'default': None}
58
 
64
 
59
 class EmField_char(EmFieldType):
65
 class EmField_char(EmFieldType):
60
 
66
 
76
     def sql_column(self):
82
     def sql_column(self):
77
         return "varchar(250) DEFAULT NULL"
83
         return "varchar(250) DEFAULT NULL"
78
 
84
 
85
+    def sqlalchemy_args(self):
86
+        return {'type_': VARCHAR(250), 'nullable': True, 'default': None}
87
+
79
 
88
 
80
 class EmField_mlstring(EmFieldType):
89
 class EmField_mlstring(EmFieldType):
81
 
90
 
93
 
102
 
94
     def sql_column(self):
103
     def sql_column(self):
95
         return "varchar(250) DEFAULT NULL"
104
         return "varchar(250) DEFAULT NULL"
105
+
106
+    def sqlalchemy_args(self):
107
+        return {'type_': VARCHAR(250), 'nullable': True, 'default': None}

Loading…
Cancel
Save