|
@@ -278,8 +278,11 @@ class DjangoMigrationHandler(object):
|
278
|
278
|
## @brief Return a good django field type given a field
|
279
|
279
|
# @param f EmField : an EmField object
|
280
|
280
|
# @param assoc_comp EmComponent : The associated component (type or class)
|
|
281
|
+ # @return A django field instance
|
|
282
|
+ # @note The manytomany fields created with the rel2type field has no related_name associated to it
|
281
|
283
|
def field_to_django(self, f, assoc_comp):
|
282
|
284
|
|
|
285
|
+ #Building the args dictionnary for django field instanciation
|
283
|
286
|
args = dict()
|
284
|
287
|
args['null'] = f.nullable
|
285
|
288
|
if not (f.default is None):
|
|
@@ -287,13 +290,22 @@ class DjangoMigrationHandler(object):
|
287
|
290
|
v_fun = f.validation_function(raise_e = ValidationError)
|
288
|
291
|
if v_fun:
|
289
|
292
|
args['validators'] = [v_fun]
|
290
|
|
-
|
291
|
|
- if f.ftype == 'char':
|
|
293
|
+ if f.uniq:
|
|
294
|
+ args['unique'] = True
|
|
295
|
+
|
|
296
|
+ # Field instanciation
|
|
297
|
+ if f.ftype == 'char': #varchar field
|
292
|
298
|
args['max_length'] = f.max_length
|
293
|
299
|
return models.CharField(**args)
|
294
|
|
- elif f.ftype == 'int':
|
|
300
|
+ elif f.ftype == 'int': #integer field
|
295
|
301
|
return models.IntegerField(**args)
|
296
|
|
- elif f.ftype == 'rel2type':
|
|
302
|
+ elif f.ftype == 'text': #text field
|
|
303
|
+ return models.TextField(**args)
|
|
304
|
+ elif f.ftype == 'datetime': #Datetime field
|
|
305
|
+ args['auto_now'] = f.now_on_update
|
|
306
|
+ args['auto_now_add'] = f.now_on_create
|
|
307
|
+ return models.DateTimeField(**args)
|
|
308
|
+ elif f.ftype == 'rel2type': #Relation to type
|
297
|
309
|
|
298
|
310
|
if assoc_comp == None:
|
299
|
311
|
raise RuntimeError("Rel2type field in a rel2type table is not allowed")
|