-
-
Notifications
You must be signed in to change notification settings - Fork 810
Consistent queryset creation in ModelAdmin export mixin #1890
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
Consistent queryset creation in ModelAdmin export mixin #1890
Conversation
…consistent-queryset-creation-1864
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this. It looks ok to me.
I added release notes and changelog updates.
I'll release this in v4.2 because it is a minor change to existing behaviour.
I did look to see whether we should remove get_valid_export_item_pks()
. It makes sense to provide a method which can be overridden by the user, but that can now be done by overriding the ModelAdmin:
class CategoryAdmin(ExportActionModelAdmin):
def get_queryset(self, request):
return Category.objects.all()
I can't see any issue with doing this if I document the change correctly.
Any thoughts?
Thank you for reviewing it, and sorry for sitting on it for so long, I had other matters to tend to.
Great! Thanks a lot!
I was thinking about this, but decided not to add it to this PR, as it would make the breaking change block the non-breaking change from being merged. The idea is that if the ModelAdmin's django-import-export/import_export/admin.py Lines 732 to 739 in b101ea2
To: if request.POST and "export_items" in request.POST:
# this field is instantiated if the export is POSTed from the
# 'action' drop down
form.fields["export_items"] = MultipleChoiceField(
widget=MultipleHiddenInput,
required=False,
choices=[(pk, pk) for pk in queryset.values_list("pk", flat=True)],
) How shall we move forward with this? Should I add the deprecation to this PR and open a new PR for the actual change? Or should I open a new PR for both? |
Yes, I think that is best if that's ok with you. |
Done. I created a PR for the removal, but that should really be based on main, after this is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment about where to put the deprecation warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your efforts on this. I added a response re the deprecation warning.
Problem
#1864
Solution
The new flow of queryset acquisition is:
export_action
callsget_export_queryset
get_export_queryset
gets the queryset from the ModelAdmin through the ModelAdmin'sChangeList
, which uses the ModelAdmin'sget_queryset
_do_file_export
whenis_skip_export_form_enabled()
isTrue
if "export_items" in form.changed_data
_do_file_export
Acceptance Criteria