saxix / django-admin-extra-urls Goto Github PK
View Code? Open in Web Editor NEWSingle mixin class to easily add buttons on any Django ModelAdmin related page
License: Other
Single mixin class to easily add buttons on any Django ModelAdmin related page
License: Other
When adding ExtraUrlMixin to a ModelAdmin the django out-of-the-box "Add " option lose its "addlink" css class. The result is that no "+" sign (tooltag-add.svg) appears in that option.
@admin.register(models.Plan)
class PlanAdmin(ExtraUrlMixin, admin.ModelAdmin):
@link(label='Recurly Sync') # /admin/myapp/mymodel/update_all/
def rsync(self, request):
try:
models.Plan.rsync(False)
self.message_user(request, "All synced!")
except RuntimeError as e:
self.message_user(request, "Sync failed: {}".format(e), level=messages.ERROR)
It would be good to add a "target" parameter for opening a new page
I have a model that has redefined the objects key as something else, and it breaks on the _inner
wrapper inside the button decorator as it specifically calls modeladmin.model.objects.get
when it should use modeladmin.get_object
https://github.com/saxix/django-admin-extra-urls/blob/develop/src/admin_extra_urls/decorators.py#L74
Versions:
django==2.0.1
admin-extra-urls==1.8.0
django-import-export==1.0.0
Problem:
I have added several @actions to my ModelAdmin (for model Post), then I added @link to integrate with django-import-export as described in Readme.md. When I follow "Export" link I get to export page successfully, but when I try to export in any format, I get error:
IncorrectLookupParameters at /admin/posts/post/_export/
Post has no field named '_changelist_filters'
import-export uses request to filter queryset as it was filtered in changelist, but extra-urls save all filters in single query parameter _changelist_filters
when building @link href. I found easy workaround, though it may be should be in docs:
from django.http.request import QueryDict
...
@link(label='Export')
def _export(self, request):
if '_changelist_filters' in request.GET:
real_query = QueryDict(request.GET.get('_changelist_filters'))
request.GET = real_query
return self.export_action(request)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.