crccheck / django-object-actions

A Django app for easily adding object tools in the Django admin
https://pypi.org/project/django-object-actions/
Apache License 2.0
669 stars 82 forks source link

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

Open platzhersh opened 8 years ago

platzhersh commented 8 years ago

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.

crccheck commented 8 years ago

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.

andybak commented 8 years ago

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)

crccheck commented 8 years ago

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.

andybak commented 8 years ago

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.

MarthinusBosman commented 2 years ago

Any progress made on this so far?

ahmedsafadii commented 2 years ago

same issue