def make_object(self, cls, fields, finalizer=None):
        obj = cls()

        for field_name, generator in fields.items():
            # Some custom processing
            field = cls._meta.get_field(field_name)
            value = generator.next()
            if isinstance(field, models.fields.related.ForeignKey) and isinstance(value, int):
                field_name = u'%s_id' % field_name
            if isinstance(field, models.fields.files.FileField):
                getattr(obj, field_name).save(*value, save=False)
            else:
                setattr(obj, field_name, value)
            try:
                self.stdout.write(u'%s: %s; ' % (field_name, value))
            except (UnicodeEncodeError, __HOLE__):
                pass

        if finalizer:
            try:
                finalizer(obj)
            except Exception as e:
                self.stdout.write(u"Error finalizing Obj %s: " % e.message)
                return False

        obj.save()
        self.stdout.write(u'\nCreated new %s: ' % obj.__class__.__name__)
dataset/ETHPy150Open sbaechler/django-scaffolding/scaffolding/management/commands/scaffold.py/Command.make_object