Fixing iteration over objects for abstract models

This commit is contained in:
Sean Bell 2013-02-09 00:55:49 -05:00
parent 969275bbc9
commit af6ebcb469
2 changed files with 15 additions and 2 deletions

View file

@ -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):

View file

@ -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('.')