Problem
Engineering context
Shared applications must prevent school records from crossing organisational boundaries.
Solution boundary
Filter the queryset by trusted school context and enforce permission separately.
Multi-Tenancy
Scopes student records to the authenticated user’s current school context.
Problem
Shared applications must prevent school records from crossing organisational boundaries.
Filter the queryset by trusted school context and enforce permission separately.
def get_queryset(self):
school = self.request.user.current_school
if not self.request.user.has_perm("students.view_student"):
raise PermissionDenied
return Student.objects.filter(school=school)
How it works
Scoping reduces the accessible dataset before object lookup.
Security considerations
Query filtering alone is insufficient; validate membership and change permission on writes.
Performance considerations
Index school foreign keys and frequent ordering columns.
Tradeoffs
Context propagation must also cover background tasks and exports.
Testing notes
Test unauthenticated, unauthorized and cross-school access.
Limitations
Illustrative public-safe example; adapt the boundary and domain rules to the actual application.
Engineering evidence
Engineering insights
Double opt-in, no list selling, and unsubscribe anytime.
Your privacy, your choice
Basic page totals are counted without identifying you. If you accept analytics, anonymous session, time, scroll, device, browser and coarse location signals help reveal what is useful. Raw IP addresses are never stored.