django-object-actions
django-object-actions copied to clipboard
django-object-actions not compatible with django-import-export
Has anyone ever tried to use django object actions together with django import export?
I have a admin class that I would like to use both of these together:
class MyClass(DjangoObjectActions, ImportExportMixin, SimpleHistoryAdmin):
Like this, I can see my django object actions, but none of the Django import export actions in the admin. When I change to this:
class MyClass(ImportExportMixin, DjangoObjectActions, SimpleHistoryAdmin):
I see my import export buttons but none of my django object actions anymore.
I suspect it's because both of us are attempting to use a custom template. I could have sworn I documented what to do in this situation, but I can't find it.
In this case, you'd have to make your own change_form.html and construct it to have all the elements you need.
- https://github.com/django-import-export/django-import-export/blob/master/import_export/templates/admin/import_export/change_list.html
- https://github.com/crccheck/django-object-actions/blob/master/django_object_actions/templates/django_object_actions/change_list.html
Could we make it a bit simpler to customize the templates? Rather than having to copy in 13 lines from your template - use an include or a templatetag so that all people have to do is add: {% include 'object_actions' %} (or {% object_actions %} if you go with an inclusion tag)
haha, I was going to say you can check out #17 but that's your PR. It's come up in other ways too so I'm leaning back towards supporting an include tag. I could have sworn there was documentation for how to customize the template but I couldn't find it the last time I looked. I'd like this to be simple enough where everything fits in the README but it's looking like that's not happening.
Quick workaround I used just now that specifically fixes this for Django Import/Export:
- Ensure DjangoObjectActions is before ExportMixin in your ModelAdmin class declaration
- Add 'redirect_to_export' to your changelist_actions
- Add the following method to your ModelAdmin
def redirect_to_export(self, request, obj):
return HttpResponseRedirect(reverse('admin:%s_%s_export' % self.get_model_info()))
redirect_to_export.label = "Export"
This works for Export but it should be clear how to do the same for import
EDIT - Damn - the redirect loses the queryset so you can't export filtered result sets. I'll think up an improved way to do this.
Any progress made on this so far?
same issue