This article can help 
: 
https://hakibenita.medium.com/how-to-add-custom-action-buttons-to-django-admin-8d266f5b0d41
 

On Thursday, 5 August 2021 at 18:31:52 UTC+5:30 arvind....@gmail.com wrote:

> hey guys i want to add the action on click the list will be filter of 
> objects
>
> here the on click of view client task i want to filter task which author 
> type is client
> Here its my try.
>
> *inherit html*
> {% extends 'admin/change_list.html' %}
>
> {% block object-tools %}
> <div>
> <form action="" method="POST">
> {% csrf_token %}
> <button type="submit" name="get_client">View Client Task</button>
> </form>
>
> </div>
> <br />
>
>
>
> *admin.py*
>
>
> *task admin*
> from django.conf.urls import patterns, url
> from django.core.urlresolvers import reverse
> class TaskAdmin(SimpleHistoryAdmin, ExportActionModelAdmin):
> change_list_template = "admin/client_task_change_list.html"
> fieldsets = (
> (
> None,
> {'fields': ('title', 'amount','word','status', 'manager', 'executive', 
> 'assignee','owner','timezone','moved_to_freelancer_portal', 
> 'can_send_without_payment', 
> 'start_date','deadline_soft','deadline_hard','client','team_lead','quality_manager','referencing_style',
>  
> 'tags')}
> ),
> (
> _('Content'),
> {'fields': ('description','author')}
> ),
> (
> _('Tracking'),
> {'fields': ('accepted_by_manager', 'accepted_by_manager_at', 
> 'completed_by_employee', 'completed_by_employee_at',\
>
> 'verified_by_manager','verified_by_manager_at','verified_by_quality','verified_by_quality_at',\
> 'sent_to_client','sent_to_client_at','completed_on')}
> ),
> )
>
> inlines = (PaymentInline,RatingInline,) 
> list_display = ('title', 'status', 'client', 'manager', 'assignee', 
> 'executive', 'team_lead', 
> 'quality_manager','get_payment_status','author','created_at','deadline_soft','deadline_hard','word')
> list_filter = ('status', 'author__type', 
> 'client__clientprofile__email_to_use', OverdueTaskListFilter,('manager', 
> admin.RelatedOnlyFieldListFilter), ('team_lead', 
> admin.RelatedOnlyFieldListFilter), ('quality_manager', 
> admin.RelatedOnlyFieldListFilter),PaymentStatusCategoryListFilter,('deadline_soft',
>  
> DateRangeFilter),('deadline_hard', DateRangeFilter), ('start_date', 
> DateRangeFilter), ('completed_on', DateRangeFilter), AuthorFilter, 
> ('owner', admin.RelatedOnlyFieldListFilter), 'moved_to_freelancer_portal')
> search_fields = ('key', 'title', 'client__username', 'client__email', 
> 'manager__email',)
> date_hierarchy = ('deadline_hard')
> resource_class = TaskResource
>
> # def get_urls(self):
>
> # urls = super(TaskAdmin,self).get_urls()
> # extra_url = patterns('',
> # # url(r'^Client/$',self.get_client_task, 
> name='get_client_task'),#self.admin_site.admin_view(self.do_evil_view))
> # url(r'^client/$',self.admin_site.admin_view(self.get_client_task)),
> # )
> # return urls + extra_url
> # def get_client_task(self, request):
> # # if 'get_client' in request.POST:
> # Task.objects.filter(author__type = UserAccount.LEVEL0)
> # # if self.model.objects.filter(author__type = 
> UserAccount.LEVEL0).exists():
> # self.message_user(request, "Here Its all Clients Tasks")
> # # else:
> # # self.message_user(request, "NO Clients Tasks")
>
> # return reverse('../')
>
> formats = (
> base_formats.CSV,
> base_formats.XLS,
> )
> raw_id_fields = ('author','assignee', 
> 'team_lead','executive','quality_manager', 'manager', 'client', 'owner', 
> 'executive', 'specification')
> history_list_display = ["history_change_reason", "word", 
> "deadline_hard","moved_to_freelancer_portal", "status"]
> #filter_horizontal = ('equipment',)
>
> # def render_change_form(self, request, context, *args, **kwargs):
> # """We need to update the context to show the button."""
> # context.update({'show_client_task': True})
> # return super().render_change_form(request, context, *args, **kwargs)
>
>
> def get_payment_status(self, obj):
> return obj.payment.get_status()
> get_payment_status.short_description = 'Payment'
> def get_queryset(self, request):
> queryset = super(TaskAdmin, self).get_queryset(
> request).annotate(feedback_count=Count('feedback'))
> # if 'get_client' in request.POST:
> # queryset.filter(author__type = UserAccount.LEVEL0)
> # return queryset
> # return queryset
>     {{ block.super }}
> {% endblock %}
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a4abd021-7623-4c41-aaa4-ecd35b519b67n%40googlegroups.com.

Reply via email to