Esempio n. 1
0
 def _process_field_with_default_fixture(self, field, model_class, persist_dependencies):
     "The field has no custom value, so the default behavior of the tool is applied."
     if field.null and not self.fill_nullable_fields:
         return None
     if field_has_default_value(field):
         if callable(field.default):
             data = field.default() # datetime default can receive a function: datetime.now
         else:
             data = field.default
     elif field_has_choices(field):
         data = field.choices[0][0] # key of the first choice
     elif is_relationship_field(field):
         data = self._process_foreign_key(model_class, field, persist_dependencies)
     else:
         data = self.data_fixture.generate_data(field)
     return data
Esempio n. 2
0
 def _process_field_with_default_fixture(self, field, model_class, persist_dependencies):
     "The field has no custom value, so the default behavior of the tool is applied."
     if field.null and not self.fill_nullable_fields:
         return None
     if field_has_default_value(field):
         if callable(field.default):
             data = field.default() # datetime default can receive a function: datetime.now
         else:
             data = field.default
     elif field_has_choices(field):
         data = field.flatchoices[0][0] # key of the first choice
     elif is_relationship_field(field):
         data = self._process_foreign_key(model_class, field, persist_dependencies)
     else:
         data = self.data_fixture.generate_data(field)
     return data
Esempio n. 3
0
 def _process_field_with_default_fixture(self, field, model_class,
                                         persist_dependencies):
     '''
     The field has no custom value (F, C, static, Lessons...), so the default behavior of the tool is applied.
     - DDF behavior priority for common fields:
     1. Use `null` if possible (considering the `fill_nullable_fields` settings)
     2. Use the `default` value
     3. Use the first option of `choices`
     - DDF behavior priority for relationship fields:
     1. Use the `default` value
     2. Use `null` if possible, or consider the `fk_min_depth` value
     3. Create a new FK model
     '''
     if is_relationship_field(field):
         if field_has_default_value(field):
             # datetime default can receive a function: datetime.now
             data = field.default() if callable(
                 field.default) else field.default
         else:
             if (not field.null) or self.fk_min_depth > 0:
                 data = self._process_foreign_key(model_class, field,
                                                  persist_dependencies)
             else:
                 data = None
     else:
         if field_has_default_value(field):
             # datetime default can receive a function: datetime.now
             data = field.default() if callable(
                 field.default) else field.default
         elif field.null and not self.fill_nullable_fields:
             data = None
         elif field_has_choices(field):
             data = field.flatchoices[0][0]  # key of the first choice
         else:
             data = self.data_fixture.generate_data(field)
     return data