SHARE
TWEET

Untitled

a guest Jan 12th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @admin.register(Salary)
  2. class SalaryAdmin (admin.ModelAdmin):
  3.     list_display = ('worker', 'salary_uah', 'dates')
  4.     search_fields = ('worker', 'salary_uah', 'dates')
  5.     list_filter = ('worker', 'date')
  6.     actions = ['button']
  7.  
  8.  
  9.     def button(self, request, queryset):
  10.  
  11.         select = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
  12.         for i in select:
  13.             return '<a  target="_blank" href="{}"></a>'.format(reverse('act', args=[i]))
  14.  
  15.     button.short_description = 'Print'
  16.     button.allow_tags = True
  17.    
  18. def acts (request, obj):
  19.     if not request.user.is_authenticated():
  20.         return redirect('admin:login')
  21.     salary = Salary.objects.get(id=obj)
  22.     workers = Worker.objects.filter(id=salary.worker.pk).values()
  23.     salary = Salary.objects.filter(id=obj).values()
  24.     return render(request, 'zpapp/act.html', {'workers':workers, 'salary':salary }
  25.    
  26. urlpatterns = [
  27.     url(r'^$',home, name='home'),
  28.     url(r'^add/$',add_worker, name='add'),
  29.     url(r'^act/(?P<obj>[w-]+)$',acts, name='act')
RAW Paste Data
Top