Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib import admin
- from .models import AddressBookAttribute
- from django.utils.html import format_html
- from django.conf.urls import url
- from django.urls import reverse
- from django.utils.translation import gettext_lazy as _
- @admin.register(AddressBookAttribute)
- class AddressBookAttributeAdmin(admin.ModelAdmin):
- readonly_fields = ('attribute_actions',)
- list_display = ('attribute', 'visible', 'available_for_group', 'sorting_index', 'attribute_actions')
- fieldsets = (
- (None, {'fields': ('attribute', 'available_for_group', 'sorting_index', 'visible')}),
- )
- def get_urls(self):
- urls = super().get_urls()
- custom_urls = [
- url(
- r'^(?P<attrinbute_id>.+)/up/$',
- self.admin_site.admin_view(self.sorted_index_up),
- name='sorted-index-up',
- ),
- url(
- r'^(?P<attrinbute_id>.+)/down/$',
- self.admin_site.admin_view(self.sorted_index_down),
- name='sorted-index-down',
- ),
- ]
- return custom_urls + urls
- def attribute_actions(self, obj):
- return format_html(
- '<a class="button" href="{}">UP</a> '
- '<a class="button" href="{}">DOWN</a>',
- reverse('admin:sorted-index-up', args=[obj.pk]),
- reverse('admin:sorted-index-down', args=[obj.pk]),
- )
- attribute_actions.short_description = _('Attribute Actions')
- attribute_actions.allow_tags = True
- def sorted_index_up(self, *args, **kwargs):
- print('up index')
- return 'up'
- def sorted_index_down(self, *args, **kwargs):
- print('down index')
- return 'text'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement