general: use django-model-utils InheritanceManager to get cells (#17645)

This commit is contained in:
Frédéric Péters 2018-01-08 16:24:55 +01:00
parent 84bb64e877
commit 6e461b07a9
3 changed files with 9 additions and 4 deletions

View File

@ -44,6 +44,8 @@ from django.forms.widgets import MediaDefiningClass
from django.template import Context, engines
from django.test.client import RequestFactory
from model_utils.managers import InheritanceManager
from .fields import RichTextField
from jsonfield import JSONField
@ -354,6 +356,8 @@ class CellBase(models.Model):
subclass = models.IntegerField(default=-1)
subclassid = models.IntegerField(default=-1)
objects = InheritanceManager()
class Meta:
abstract = False
@ -391,11 +395,10 @@ class CellBase(models.Model):
def get_cells(cls, cell_filter=None, **kwargs):
"""Returns the list of cells of various classes matching **kwargs"""
cells = []
for klass in get_cell_classes():
if cell_filter and not cell_filter(klass):
for cell in cls.objects.filter(**kwargs).order_by('order').select_subclasses():
if cell_filter and not cell_filter(cell):
continue
cells.extend(klass.objects.filter(**kwargs))
cells.sort(lambda x, y: cmp(x.order, y.order))
cells.append(cell)
return cells
def get_reference(self):

1
debian/control vendored
View File

@ -11,6 +11,7 @@ Architecture: all
Depends: ${misc:Depends}, ${python:Depends},
python-django (>= 1.8), python-django (<< 1.9),
python-djangorestframework (>= 3.3),
python-django-model-utils,
python-gadjo,
python-requests,
python-feedparser,

View File

@ -105,6 +105,7 @@ setup(
],
install_requires=['django>=1.8, <1.12',
'django-ckeditor<4.5.3',
'django-model-utils',
'gadjo',
'feedparser',
'django-jsonfield',