def guessFieldFormatters(self, generator):

        formatters = {}
        model = self.model
        nameGuesser = Name(generator)
        fieldTypeGuesser = FieldTypeGuesser(generator)

        for field in model._meta.fields:
        #            yield field.name, getattr(self, field.name)
            fieldName = field.name
            if isinstance(field, (ForeignKey,ManyToManyField,OneToOneField)):
                relatedModel = field.rel.to

                def build_relation(inserted):
                    if relatedModel in inserted and inserted[relatedModel]:
                        return relatedModel.objects.get(pk=random.choice(inserted[relatedModel]))
                    if not field.null:
                        try :
                            # try to retrieve random object from relatedModel
                            relatedModel.objects.order_by('?')[0]
                        except __HOLE__:
                            raise Exception('Relation "%s.%s" with "%s" cannot be null, check order of addEntity list' % (
                                field.model.__name__, field.name, relatedModel.__name__,
                            ))
                    return None

                formatters[fieldName] = build_relation
                continue

            if isinstance(field, AutoField):
                continue

            formatter = nameGuesser.guessFormat(fieldName)
            if formatter:
                formatters[fieldName] = formatter
                continue

            formatter = fieldTypeGuesser.guessFormat(field)
            if formatter:
                formatters[fieldName] = formatter
                continue

        return formatters
dataset/ETHPy150Open joke2k/django-faker/django_faker/populator.py/ModelPopulator.guessFieldFormatters