8

add custom model manager

This commit is contained in:
Paul J Stevens
2018-05-26 12:01:26 +02:00
parent 9710d3b479
commit bb34bddaf4
2 changed files with 19 additions and 10 deletions

View File

@@ -1,10 +1,12 @@
from __future__ import absolute_import, unicode_literals
import random
from django import forms
from django.conf import settings
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models, transaction
from django.db.models import F
from django.template.defaultfilters import slugify
from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property
@@ -199,6 +201,16 @@ class Segment(ClusterableModel):
return False
class PersonalisablePageManager(models.Manager):
def canonicals(self):
return (
self.filter(
personalisable_canonical_metadata__canonical_page_id=F(
'personalisable_canonical_metadata__variant__id'))
)
class PersonalisablePageMetadata(ClusterableModel):
"""The personalisable page model. Allows creation of variants with linked
segments.
@@ -219,6 +231,8 @@ class PersonalisablePageMetadata(ClusterableModel):
on_delete=models.SET_NULL,
null=True, blank=True)
objects = PersonalisablePageManager()
@cached_property
def has_variants(self):
"""Return a boolean indicating whether or not the personalisable page