Skip to content

Commit

Permalink
Merge branch 'release/0.3.22' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jul 5, 2023
2 parents cd40545 + a1cfc85 commit de7442f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions edc_sites/modeladmin_mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections

from django.contrib import admin
from django.core.exceptions import FieldError

from .get_country import get_current_country
from .get_language_choices_for_site import get_language_choices_for_site
Expand Down Expand Up @@ -30,9 +31,13 @@ def site_code(self, obj=None):

def get_queryset(self, request):
"""Limit modeladmin queryset for the current site only"""
qs = super().get_queryset(request)
if getattr(request, "site", None):
return super().get_queryset(request).filter(site_id=request.site.id)
return super().get_queryset(request)
try:
qs = qs.filter(site_id=request.site.id)
except FieldError:
pass
return qs

def get_form(self, request, obj=None, change=False, **kwargs):
"""Add current_site attr to form instance"""
Expand Down

0 comments on commit de7442f

Please sign in to comment.