Unverified Commit c57b2d99 authored by Julien Palard's avatar Julien Palard
Browse files

admin: FIX: filtering on exercises and filtering on users is not the same.

parent 8d30d5c9
from django import forms
from django.core.exceptions import FieldError
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.safestring import mark_safe
......@@ -186,8 +187,12 @@ class TeamFilter(admin.SimpleListFilter):
return [(team.id, team.name) for team in Team.objects.my_teams(request.user)]
def queryset(self, request, queryset):
if self.value() is not None:
return queryset.filter(user__teams=self.value())
try: # to filter on objects having a user property:
if self.value() is not None:
return queryset.filter(user__teams=self.value())
except FieldError: # to filter on users
if self.value() is not None:
return queryset.filter(teams=self.value())
class MyExercisesFilter(admin.SimpleListFilter):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment