New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include custom form media in templates #1038
Include custom form media in templates #1038
Conversation
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey @andreynovikov . Thanks for the PR. When you say
Can you give an example of this and some screeshots? Also how does this effect current/standard behavior? |
I've also ran into this problem. @andrewgy8 you can recreate this in the test app by updating
If the form media is loaded correctly, the field should use the nice autocomplete widget you get in an edit form when you use |
Hey! Is this safe to be merged to master? |
I would be OK with including this but I would like to understand exactly how it works. Can anyone supply steps to reproduce / screenshots / or a more detailed explanation of what's going on. I read Andy's comment but I'm still not clear on what the nature of this change is. |
@matthewhegarty In a nutshell, Django has a mechanism that allows form widgets to register additional JS and CSS so that they can function properly. However, if you do not render |
@ababic Andy - thanks for the explanation, I understand what's going on now. I was able to reproduce the issue in the v3 codebase as follows (adapted from Andy's post):
class AuthorFormMixin(forms.Form):
author = forms.ModelChoiceField(
queryset=Author.objects.all(),
widget=AutocompleteSelect(Book._meta.get_field('author'), admin.site)
)
#...
class CustomExportForm(AuthorFormMixin, ExportForm):
"""Customized ExportForm, with author field required"""
pass
class AuthorAdmin(ImportMixin, admin.ModelAdmin):
search_fields = ['name']
class CustomBookAdmin(BookAdmin):
"""BookAdmin with custom import forms"""
autocomplete_fields = ['author']
# ...
def get_export_form(self):
return CustomExportForm (then add the PR changes to This results in the correct autocomplete widget being show, with 'author' values being dynamically populated. |
I've updated this PR with merges from v3. |
Thank you @andreynovikov and @ababic |
Thanks @matthewhegarty! Happy Easter to you :) |
Problem
When custom import/export forms contain complex widgets with linked media it is not added to output.
Solution
Added standard form.media to templates.
Acceptance Criteria
This fix does not require tests and documentation changes.