Skip to content

Commit 7b6a424

Browse files
committed
invites now are filtered by current user by default
1 parent 194e20a commit 7b6a424

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

invites/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
@admin.register(Invite)
77
class InviteAdmin(admin.ModelAdmin):
8-
fields = [""]
8+
fields = ["project", "user", "motivational_letter", "role", "is_accepted"]

invites/filters.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ class InviteFilter(filters.FilterSet):
1717
?is_active=false equals to .filter(is_active=False)
1818
"""
1919

20-
is_active = filters.BooleanFilter(field_name="is_active")
20+
def __init__(self, *args, **kwargs):
21+
"""if is_active filter is not passed, default to True"""
22+
super().__init__(*args, **kwargs)
23+
# if self.data.get("is_active") is None:
24+
if self.data.get("user") is None:
25+
# default filtering by current user
26+
self.data = dict(self.data)
27+
self.data["user"] = kwargs.get("request").user.id
2128

2229
class Meta:
2330
model = Invite
24-
fields = ("project", "is_active")
31+
fields = ("project", "user")

0 commit comments

Comments
 (0)