mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-02 21:10:31 +00:00
Fixing iteration over objects for abstract models
This commit is contained in:
parent
969275bbc9
commit
af6ebcb469
2 changed files with 15 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ from django.db.models.signals import post_init, post_save, post_delete
|
|||
from django.utils.functional import wraps
|
||||
from ..cachefiles import LazyImageCacheFile
|
||||
from ..signals import source_created, source_changed, source_deleted
|
||||
from ..utils import get_nonabstract_descendants
|
||||
|
||||
|
||||
def ik_model_receiver(fn):
|
||||
|
|
@ -131,8 +132,9 @@ class ImageFieldSourceGroup(object):
|
|||
particular model.
|
||||
|
||||
"""
|
||||
for instance in self.model_class.objects.all():
|
||||
yield getattr(instance, self.image_field)
|
||||
for model in get_nonabstract_descendants(self.model_class):
|
||||
for instance in model.objects.all().iterator():
|
||||
yield getattr(instance, self.image_field)
|
||||
|
||||
|
||||
class SourceGroupFilesGenerator(object):
|
||||
|
|
|
|||
|
|
@ -23,6 +23,17 @@ def _get_models(apps):
|
|||
return models
|
||||
|
||||
|
||||
def get_nonabstract_descendants(model):
|
||||
""" Returns all non-abstract descendants of the model. """
|
||||
if model._meta.abstract:
|
||||
descendants = []
|
||||
for m in model.__subclasses__():
|
||||
descendants += get_nonabstract_descendants(m)
|
||||
return descendants
|
||||
else:
|
||||
return [model]
|
||||
|
||||
|
||||
def get_by_qname(path, desc):
|
||||
try:
|
||||
dot = path.rindex('.')
|
||||
|
|
|
|||
Loading…
Reference in a new issue