The querysets represented herein are designed to be used with their appropriate abstract models, and typically provide additional methods by which to filter objects.
The obvious way to get these yourself is to create your own subclass which implements them, and wire it up to a manager:
from helpfulfields.querysets import (ChangeTrackingQuerySet,
DatePublishingQuerySet,
SoftDeleteQuerySet)
class MyCustomQS(ChangeTrackingQuerySet, DatePublishingQuerySet, SoftDeleteQuerySet):
pass
class MyCustomManager(Manager):
def get_query_set(self):
return MyCustomQS(self.model)
def created_recently(self, minutes=30):
# this method is exposed via ChangeTrackingQuerySet
return self.get_query_set().created_recently(minutes=minutes)
#[...]
class MyModel(Model):
objects = MyCustomManager()
Better than doing it all yourself though, is just to use a PassThroughManager from django-model-utils to reduce the amount of repetition involved:
from model_utils.managers import PassThroughManager
from helpfulfields.querysets import (ChangeTrackingQuerySet,
DatePublishingQuerySet,
SoftDeleteQuerySet)
class MyCustomQS(ChangeTrackingQuerySet, DatePublishingQuerySet, SoftDeleteQuerySet):
pass
class MyModel(Model):
objects = PassThroughManager.for_queryset_class(MyCustomQS)()
A custom queryset for filtering models using the ChangeTracking model.
Goes hand in hand with the created_recently() method. Finds all object instances created within the last N minutes.
Accepts a list of kwargs which are passed directly to timedelta; in the absence of any kwargs the timedelta is told 30 minutes is recent.
Returns: | filtered objects |
---|---|
Return type: | QuerySet subclass |
Goes hand in hand with the modified_recently() method. Finds all object instances modified within the last N minutes.
Accepts a list of kwargs which are passed directly to timedelta; in the absence of any kwargs the timedelta is told 30 minutes is recent.
Returns: | filtered objects |
---|---|
Return type: | QuerySet subclass |
A custom queryset for filtering things using the DatePublishing abtract model via the new fields it provides.
Find all objects whose unpublish_on value is in the future, or is null, and also have a publish_on value which is in the past or present.
Returns: | All published objects |
---|---|
Return type: | QuerySet subclass |
Find all objects whose unpublish_on value is in the past, or alternatively have a publish_on value which is still in the future.
Returns: | All unpublished objects |
---|---|
Return type: | QuerySet subclass |
A custom queryset for filtering things using the Publishing abstract model via it’s boolean.
Find all objects who have have is_published set to True.
Returns: | All published objects |
---|---|
Return type: | QuerySet subclass |
Find all objects who have have is_published set to False.
Returns: | All published objects |
---|---|
Return type: | QuerySet subclass |
A custom queryset which goes hand in hand with the SoftDelete model to provide a way to filter by the additional field that creates.
Warning
This should not be relied on to prevent data loss, as it is very much an incomplete idea right now.
Finds all objects which haven’t been marked as deleted. This includes those which have been restored previously.
Returns: | objects which haven’t been marked as deleted |
---|---|
Return type: | QuerySet subclass |