gault-millau/apps/utils/querysets.py

18 lines
594 B
Python

"""Utils QuerySet Mixins"""
from django.db import models
from utils.methods import get_contenttype
class ContentTypeQuerySetMixin(models.QuerySet):
"""QuerySet for ContentType"""
def by_object_id(self, object_id: int):
"""Filter by object_id"""
return self.filter(object_id=object_id)
def by_content_type(self, app_label: str = 'favorites', model: str = 'favorites'):
"""Filter QuerySet by ContentType."""
return self.filter(content_type=get_contenttype(app_label=app_label,
model=model))