def process_module(self, module): seeds = {} real_clazzes = [clazz for clazz in dir(module) if not clazz.startswith("__")] for name in real_clazzes: obj = getattr(module, name) if inspect.isclass(obj) and (obj != Seed) and issubclass(obj, Seed): seeds[model_namespace(obj.model)] = obj self.seeds.update(seeds)
def handle_m2m_field(self, obj, field): if field.rel.through._meta.auto_created: if hasattr(self, 'use_natural_keys') and self.use_natural_keys and hasattr(field.rel.to, 'natural_key'): m2m_value = lambda value: value.natural_key() else: m2m_value = lambda value: smart_unicode(value._get_pk_val(), strings_only=True) dirt_key = model_namespace(field.rel.to) dirt = self.dirt obj_set = dirt.soil.objects.get(dirt_key, set()) self._current[field.name] = [m2m_value(related) for related in getattr(obj, field.name).iterator() if related.pk in obj_set]