Add multiple trash can support, restoring and complete source object manager and queryset method substitution
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class CustomizableQuerySetManager(models.Manager):
|
||||
# FROM: https://gist.github.com/2587518
|
||||
# AUTHOR: https://gist.github.com/fission6
|
||||
# http://docs.djangoproject.com/en/dev/topics/db/managers/#using-managers-for-related-object-access
|
||||
# Not working cause of:
|
||||
# http://code.djangoproject.com/ticket/9643
|
||||
use_for_related_fields = True
|
||||
|
||||
def __init__(self, qs_class=models.query.QuerySet):
|
||||
self.queryset_class = qs_class
|
||||
super(CustomizableQuerySetManager, self).__init__()
|
||||
|
||||
def get_query_set(self):
|
||||
return self.queryset_class(self.model)
|
||||
|
||||
def __getattr__(self, attr, *args):
|
||||
try:
|
||||
return getattr(self.__class__, attr, *args)
|
||||
except AttributeError:
|
||||
return getattr(self.get_query_set(), attr, *args)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from .managers import CustomizableQuerySetManager
|
||||
|
||||
|
||||
class CustomizableQuerySet(QuerySet):
|
||||
"""Base QuerySet class for adding custom methods that are made
|
||||
available on both the manager and subsequent cloned QuerySets"""
|
||||
|
||||
@classmethod
|
||||
def as_manager(cls, ManagerClass=CustomizableQuerySetManager):
|
||||
return ManagerClass(cls)
|
||||
Reference in New Issue
Block a user