Customize admin import forms problem
See original GitHub issueFollowing the docs (getting started) in the last section I got a problem. Everything works fine and the Author form shows normally but when I select the author and send an .xlsx file it doesn’t update the author field even after I confirm the import, it doesn’t update the author field. and this’s the code that I’m talking about from the docs :
from import_export.admin import ImportMixin
from import_export.forms import ImportForm
from import_export.forms import ConfirmImportForm
from django import forms
class CustomImportForm(ImportForm):
author = forms.ModelChoiceField(
queryset=Author.objects.all(),
required=True)
class CustomConfirmImportForm(ConfirmImportForm):
author = forms.ModelChoiceField(
queryset=Author.objects.all(),
required=True)
class BookResource(resources.ModelResource):
class Meta:
model = Book
class CustomBookAdmin(ImportMixin, admin.ModelAdmin):
resource_class = BookResource
def get_import_form(self):
return CustomImportForm
def get_confirm_import_form(self):
return CustomConfirmImportForm
def get_form_kwargs(self, form, *args, **kwargs):
# pass on `author` to the kwargs for the custom confirm form
if isinstance(form, CustomImportForm):
if form.is_valid():
author = form.cleaned_data['author']
kwargs.update({'author': author.id})
return kwargs
admin.site.register(Book, CustomBookAdmin)```
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Customize admin import forms - django - Stack Overflow
I want to add an additional field to my Import-Form on the Admin page. I did everything the Docs ...
Read more >Add field value from import form #758 - GitHub
I am having a bit trouble implementing this. I see the custom field on the import form, but the value does not get...
Read more >Creating forms from models - Django documentation
forms import BaseModelFormSet class MyModelFormSet(BaseModelFormSet): def clean(self): super().clean() # example custom validation across forms in the formset ...
Read more >Django Tutorial Part 9: Working with forms - MDN Web Docs
Create and open the file locallibrary/catalog/forms.py. To create a Form , we import the forms library, derive from the Form class, and declare ......
Read more >What You Need to Know to Manage Users in Django Admin
For example, the User model is imported from the auth app ( django.contrib.auth ). <action> is one of the actions above ( add...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Interesting. I was working on another lib a few weeks ago, and ran into an issue with
isinstance
usage. I had to also useissubclass
. Could it be related?Hi, I have similar issue. My problem that a get form class but not form class instance onto the
form
argument ofget_form_kwargs
method.