'Hook for specifying the form Field instance for a given database Field
instance.
If kwargs are given, they\'re passed to the form Field\'s constructor.'

def formfield_for_dbfield(self, db_field, **kwargs):

    request = kwargs.pop('request', None)
    if db_field.choices:
        return self.formfield_for_choice_field(db_field, request, **kwargs)
    if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
        if (db_field.__class__ in self.formfield_overrides):
            kwargs = dict(self.formfield_overrides[db_field.__class__], **kwargs)
        if isinstance(db_field, models.ForeignKey):
            formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)
        elif isinstance(db_field, models.ManyToManyField):
            formfield = self.formfield_for_manytomany(db_field, request, **kwargs)
        if (formfield and (db_field.name not in self.raw_id_fields)):
            related_modeladmin = self.admin_site._registry.get(db_field.rel.to)
            can_add_related = bool((related_modeladmin and related_modeladmin.has_add_permission(request)))
            formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site, can_add_related=can_add_related)
        return formfield
    for klass in db_field.__class__.mro():
        if (klass in self.formfield_overrides):
            kwargs = dict(copy.deepcopy(self.formfield_overrides[klass]), **kwargs)
            return db_field.formfield(**kwargs)
    return db_field.formfield(**kwargs)
