From 22a0e910a5be3cfad4090ee4750686b93fa3e652 Mon Sep 17 00:00:00 2001 From: Calum Mackervoy <c.mackervoy@gmail.com> Date: Wed, 8 Apr 2020 10:41:29 +0100 Subject: [PATCH] overriding Model.objects to provide local() convenience function --- djangoldp/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/djangoldp/models.py b/djangoldp/models.py index 4bc67125..f76de19f 100644 --- a/djangoldp/models.py +++ b/djangoldp/models.py @@ -13,8 +13,17 @@ from djangoldp.fields import LDPUrlField from djangoldp.permissions import LDPPermissions +class LDPModelManager(models.Manager): + # an alternative to all() which exlcudes external resources + def local(self): + queryset = super(LDPModelManager, self).all() + internal_ids = [x.pk for x in queryset if not Model.is_external(x)] + return queryset.filter(pk__in=internal_ids) + + class Model(models.Model): urlid = LDPUrlField(blank=True, null=True, unique=True) + objects = LDPModelManager() def __init__(self, *args, **kwargs): super(Model, self).__init__(*args, **kwargs) -- GitLab