-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic admin and model __str__ methods (#2)
* Add basic admin and model __str__ methods * Bump version number
- Loading branch information
1 parent
5908b0a
commit abef054
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from django.contrib import admin | ||
|
||
from . import models | ||
|
||
|
||
class ZendeskUserAdmin(admin.ModelAdmin): | ||
|
||
list_display = [ | ||
"zendesk_id", | ||
"name", | ||
"email", | ||
"active", | ||
"role", | ||
"user", | ||
"created_at", | ||
] | ||
list_filter = ["active", "role", "created_at"] | ||
raw_id_fields = ["user"] | ||
search_fields = ["zendesk_id", "name", "email"] | ||
|
||
def get_queryset(self, request): | ||
return models.ZendeskUser.objects.all().select_related("user") | ||
|
||
|
||
class TicketAdmin(admin.ModelAdmin): | ||
|
||
list_display = [ | ||
"zendesk_id", | ||
"requester", | ||
"subject", | ||
"status", | ||
"created_at", | ||
"updated_at", | ||
] | ||
list_filter = ["status", "created_at", "updated_at"] | ||
# for Django <2.1 | ||
raw_id_fields = ["requester"] | ||
# for Django >=2.1 | ||
autocomplete_fields = ["requester"] | ||
search_fields = ["ticket__subject", "ticket__zendesk_id"] | ||
|
||
def get_queryset(self, request): | ||
return models.Ticket.objects.all().select_related("requester") | ||
|
||
|
||
class CommentAdmin(admin.ModelAdmin): | ||
list_display = ["zendesk_id", "ticket_id", "author", "body", "public", "created_at"] | ||
list_filter = ["public", "created_at"] | ||
# for Django <2.1 | ||
raw_id_fields = ["ticket", "author"] | ||
# for Django >=2.1 | ||
autocomplete_fields = ["ticket", "author"] | ||
|
||
def get_queryset(self, request): | ||
return models.Comment.objects.all().select_related("ticket", "author") | ||
|
||
|
||
class EventAdmin(admin.ModelAdmin): | ||
list_display = ["remote_ticket_id", "processing_ok", "created_at", "updated_at"] | ||
list_filter = ["created_at", "updated_at"] | ||
# for Django <2.1 | ||
raw_id_fields = ["ticket"] | ||
# for Django >=2.1 | ||
autocomplete_fields = ["ticket"] | ||
|
||
def processing_ok(self, instance): | ||
return False if instance.error else True | ||
|
||
processing_ok.boolean = True | ||
|
||
|
||
admin.site.register(models.ZendeskUser, ZendeskUserAdmin) | ||
admin.site.register(models.Ticket, TicketAdmin) | ||
admin.site.register(models.Comment, CommentAdmin) | ||
admin.site.register(models.Event, EventAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters