django-object-actions icon indicating copy to clipboard operation
django-object-actions copied to clipboard

django-object-actions not compatible with django-import-export

Open platzhersh opened this issue 9 years ago • 6 comments

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.

platzhersh avatar Jun 20 '16 12:06 platzhersh

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

crccheck avatar Jun 29 '16 04:06 crccheck

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)

andybak avatar Jul 17 '16 10:07 andybak

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.

crccheck avatar Jul 17 '16 13:07 crccheck

Quick workaround I used just now that specifically fixes this for Django Import/Export:

  1. Ensure DjangoObjectActions is before ExportMixin in your ModelAdmin class declaration
  2. Add 'redirect_to_export' to your changelist_actions
  3. 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.

andybak avatar Sep 05 '16 15:09 andybak

Any progress made on this so far?

MarthinusBosman avatar Apr 05 '22 16:04 MarthinusBosman

same issue

ahmedsafadii avatar Aug 30 '22 18:08 ahmedsafadii