Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛(dashboard) adjust manager order in Consent model #306

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dashboard/apps/consent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class Consent(DashboardBase):
end = models.DateTimeField(_("end date"))
revoked_at = models.DateTimeField(_("revoked at"), null=True, blank=True)

active_objects = ConsentManager()
# models.Manager() must be in first place to ensure django admin expectations.
objects = models.Manager()
active_objects = ConsentManager()

class Meta: # noqa: D106
ordering = ["delivery_point"]
Expand Down
31 changes: 31 additions & 0 deletions src/dashboard/apps/consent/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Dashboard consent admin tests."""

import pytest
from django.contrib.admin.sites import AdminSite
from django.urls import reverse

from apps.consent.admin import ConsentAdmin
from apps.consent.models import Consent


@pytest.mark.django_db
def test_admin_manager_name(rf):
"""Tests the name of the manager used by the Django admin to retrieve objects.

For the Django admin, the manager used must be the default django manager
(`objects`) and not a custom manager, which could lead to an unwanted loss of
display of data.
"""
# Initialize admin
site = AdminSite()
admin = ConsentAdmin(Consent, site)

# Request admin consent
request = rf.get(reverse("admin:qcd_consent_consent_changelist"))

# Get the queryset used by admin
queryset = admin.get_queryset(request)

# The manager name must be the default Django manager: `objects`.
manager_name = queryset.model._default_manager.name
assert manager_name == "objects"
Loading