Implement hiding and showing functionality for user exams and collections

This commit is contained in:
Ross
2026-06-15 11:23:00 +01:00
parent 35ab7443d2
commit c50ace771e
11 changed files with 400 additions and 50 deletions
+31
View File
@@ -698,6 +698,12 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
default=True,
)
@property
def content_type_id(self) -> int:
from django.contrib.contenttypes.models import ContentType
return ContentType.objects.get_for_model(self).id
authors_only = models.BooleanField(
help_text="If true only exam/collection authors will be able to view.",
default=False,
@@ -2390,3 +2396,28 @@ class FindingBase(models.Model):
return get_pretty_json(json.loads(self.viewport_json))
except Exception:
return ""
class UserHiddenItem(models.Model):
"""Model to track which exams or collections have been hidden by a user.
"""
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="hidden_items",
)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey("content_type", "object_id")
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["user", "content_type", "object_id"],
name="unique_user_hidden_item",
)
]
def __str__(self):
return f"{self.user} hid {self.content_object}"