Skip to content

Commit

Permalink
Merge pull request #28 from City-of-Turku/feature/admin-ordering
Browse files Browse the repository at this point in the history
Feature/admin ordering
  • Loading branch information
juuso-j authored Mar 6, 2024
2 parents f795d93 + a83e44d commit ca17a5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 11 additions & 2 deletions account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@

from .models import MailingList, Profile, User

admin.site.register(User)

class UserAdmin(admin.ModelAdmin):
list_display = ("username", "date_joined")
ordering = ["-date_joined"]


class ProfileAdmin(admin.ModelAdmin):
list_display = ("user", "result")
list_display = ("user", "result", "date_joined")

ordering = ["-user__date_joined"]

def result(self, obj):
if obj.user.result:
return obj.user.result.value
else:
return None

def date_joined(self, obj):
return obj.user.date_joined


class MailingListAdminForm(forms.ModelForm):
csv_emails = forms.CharField(widget=forms.Textarea(attrs={"rows": 20, "cols": 120}))
Expand Down Expand Up @@ -52,5 +60,6 @@ def has_delete_permission(self, request, obj=None):
return False


admin.site.register(User, UserAdmin)
admin.site.register(Profile, ProfileAdmin)
admin.site.register(MailingList, MailingListAdmin)
12 changes: 9 additions & 3 deletions profiles/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,22 @@ class AnswerOtherAdmin(
DisableAddAdminMixin,
admin.ModelAdmin,
):
queryset = Answer.objects.filter(other__isnull=False)
ordering = ["question", "sub_question"]

actions = ["export_as_csv"]
list_per_page = 10000
list_display = (
"question_number",
"question_description",
"sub_question_description",
"other",
)

def question_number(self, obj):
if obj.sub_question:
return obj.sub_question.question.number
return obj.question.number

def export_as_csv(self, request, queryset):
meta = self.model._meta
queryset = queryset.order_by("question", "sub_question")
Expand Down Expand Up @@ -143,8 +150,7 @@ def export_as_csv(self, request, queryset):

def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.filter(option__is_other=True)
return qs
return qs.filter(option__is_other=True)

def other(self, obj):
return obj.option.other
Expand Down

0 comments on commit ca17a5f

Please sign in to comment.