2018-10-29 13:35:18 +00:00
|
|
|
from django.db import models
|
|
|
|
from django_kepi import object_type_registry
|
2018-10-29 14:28:13 +00:00
|
|
|
from django_kepi.cache_model import Cache
|
2018-10-29 13:35:18 +00:00
|
|
|
|
|
|
|
#######################
|
|
|
|
|
2018-10-29 14:28:13 +00:00
|
|
|
class SomethingManager(models.Manager):
|
2018-10-29 13:35:18 +00:00
|
|
|
|
2018-10-29 14:28:13 +00:00
|
|
|
f_type = None
|
2018-10-29 13:35:18 +00:00
|
|
|
|
|
|
|
def get_queryset(self):
|
2018-10-29 14:28:13 +00:00
|
|
|
# TODO augment QSs with contenttypes link to source
|
2018-10-29 13:35:18 +00:00
|
|
|
|
2018-10-29 14:39:52 +00:00
|
|
|
result = models.QuerySet(
|
|
|
|
model = self.parent_model,
|
|
|
|
)
|
2018-10-29 14:28:13 +00:00
|
|
|
|
2018-10-29 14:39:52 +00:00
|
|
|
handlers = [
|
|
|
|
Cache.objects.filter(f_type=self.f_type),
|
|
|
|
]
|
2018-10-29 14:28:13 +00:00
|
|
|
|
2018-10-29 14:39:52 +00:00
|
|
|
handlers.extend([
|
|
|
|
h.objects.all()
|
|
|
|
for h in object_type_registry[self.f_type]])
|
2018-10-29 13:35:18 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
#######################
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
|
|
|
|
f_type = 'Person'
|
2018-10-29 14:28:13 +00:00
|
|
|
objects = SomethingManager()
|
|
|
|
objects.f_type = f_type
|
2018-10-29 13:35:18 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-10-29 14:28:13 +00:00
|
|
|
managed = False
|
2018-10-29 14:39:52 +00:00
|
|
|
|
|
|
|
Person.objects.parent_model = Person # this is ugly
|
|
|
|
|