Browse Source

Added default values for django models Field types

Roland Haroutiounian 9 years ago
parent
commit
946cc49a88
1 changed files with 9 additions and 0 deletions
  1. 9
    0
      EditorialModel/fields.py

+ 9
- 0
EditorialModel/fields.py View File

@@ -65,6 +65,15 @@ class EmField(EmComponent):
65 65
         return True
66 66
 
67 67
     def to_django(self):
68
+        if self.fieldtype in ('varchar', 'char'):
69
+            max_length = None if 'max_length' not in self.options else self.options['max_length']
70
+            return self.fieldtypes[self.fieldtype](max_length=max_length, **self.options)
71
+
72
+        if self.fieldtype in ('time', 'datetime', 'date'):
73
+            auto_now = False if 'auto_now' not in self.options else self.options['auto_now']
74
+            auto_now_add = False if 'auto_now_add' not in self.options else self.options['auto_now_add']
75
+            return self.fieldtypes[self.fieldtype](auto_now=auto_now, auto_now_add=auto_now_add, **self.options)
76
+
68 77
         if self.fieldtype == 'boolean' and ('nullable' in self.options and self.options['nullable'] == 1):
69 78
             return models.NullBooleanField(**self.options)
70 79
 

Loading…
Cancel
Save