Extending the admin import form for django import_export
<p>I'm using <a href="https://github.com/django-import-export/django-import-export" rel="noreferrer">Django import_export</a> to implement CSV upload in my admin pages. Now I have one model, that contains a foreign key column, but the foreign key column will have only one value for each import. Therefore I would like to allow the user to choose the related model instance from a drop-down instead of forcing the user to append the columns themselves. In order to do this I need to customize the import form, which requires overriding the default methods <code>import_action</code> and <code>process_import</code>, but my efforts so far have shown no effect. Here is what I have so far: </p>

<pre><code>from django import forms
from import_export.forms import ImportForm  
from .models import MyModel, RelatedModel

class CustomImportForm(ImportForm):
    """Add a model choice field for a given model to the standard form."""
    appended_instance = forms.ModelChoiceField(queryset=None)

    def __init__(self, choice_model, import_formats, *args, **kwargs):
        super(CustomImportForm, self).__init__(import_formats, *args, **kwargs)
        self.fields['appended_instance'].queryset = choice_model.objects.all()

@admin.register(MyModel)
class MyModelAdmin(ImportExportModelAdmin):
    resource_class = SomeResource


    def import_action(self, request, *args, **kwargs):
        super().import_action(self, request, *args, **kwargs)
        form = CustomImportForm(RelatedModel, 
                                import_formats,
                                request.POST or None,
                                request.FILES or None)
</code></pre>

<p>Now when I go the import page I get the <code>AttributeError MyModelAdmin has no attribute 'POST'</code> and in the local vars I can see that the <code>request object</code> is actually the <code>MyModelAdmin</code> class, which is I believe is not what it's supposed to be.</p>