class WidgyPage(WidgyPageMixin, Page): root_node = VersionedWidgyField( site=settings.WIDGY_MEZZANINE_SITE, verbose_name=_('widgy content'), root_choices=( 'page_builder.Layout', ), # WidgyField used to have these as defaults. null=True, on_delete=models.SET_NULL, ) class Meta: verbose_name = _('widgy page') verbose_name_plural = _('widgy pages') swappable = 'WIDGY_MEZZANINE_PAGE_MODEL' _base_manager = UseForRelatedFieldsSelectRelatedManager(select_related=[ 'root_node', 'root_node__head', # we might not need this, if head isn't published, but we # probably will. 'root_node__head__root_node', ]) objects = PageManager()
class VersionedPage(models.Model): version_tracker = VersionedWidgyField( site='modeltests.core_tests.widgy_config.widgy_site', root_choices=[Layout, AnotherLayout], blank=True, null=True, )
class News(AbstractBlog): content = VersionedWidgyField( null=False, on_delete=models.PROTECT, site=site, verbose_name='News Content', root_choices=[ 'NewsLayout', ], )
class Blog(AbstractBlog): content = VersionedWidgyField( on_delete=models.PROTECT, site=site, root_choices=[ 'BlogLayout', ], ) class Meta: verbose_name = 'blog post' verbose_name_plural = 'blog posts' @property def author(self): return self.content.working_copy.content.author
class RawPage(WidgyPageMixin, Page): HTML = 'text/html' PLAIN_TEXT = 'text/plain' JSON = 'application/json' XML = 'application/xml' CONTENT_TYPE_CHOICES = ((HTML, _('HTML')), (PLAIN_TEXT, _('Plain text')), (JSON, _('JSON')), (XML, _('XML'))) root_node = VersionedWidgyField( site=settings.WIDGY_MEZZANINE_SITE, verbose_name=_('widgy content'), root_choices=('page_builder.MainContent', ), # WidgyField used to have these as defaults. null=True, on_delete=models.SET_NULL, ) response_content_type = models.CharField( verbose_name=_('Response content type'), max_length=255, choices=CONTENT_TYPE_CHOICES, default=HTML) class Meta: verbose_name = _('raw page') verbose_name_plural = _('raw pages') swappable = 'WIDGY_MEZZANINE_PAGE_MODEL' _base_manager = UseForRelatedFieldsSelectRelatedManager(select_related=[ 'root_node', 'root_node__head', # we might not need this, if head isn't published, but we # probably will. 'root_node__head__root_node', ]) objects = PageManager()
class ReviewedVersionedPage(models.Model): version_tracker = VersionedWidgyField( site='modeltests.core_tests.widgy_config.widgy_site', root_choices=[Layout, AnotherLayout], to='review_queue.ReviewedVersionTracker', )
class VersionPageThrough(models.Model): widgy = VersionedWidgyField(site='modeltests.core_tests.widgy_config.widgy_site', related_name='+') page = models.ForeignKey(VersionedPage4)
class VersionedPage3(models.Model): foo = VersionedWidgyField(site='modeltests.core_tests.widgy_config.widgy_site', related_name='+')
class VersionedPage2(models.Model): bar = VersionedWidgyField(site='modeltests.core_tests.widgy_config.widgy_site', related_name='asdf', null=True)
from widgy.site import WidgySite from widgy.db.fields import VersionedWidgyField, WidgyField widgy_site = WidgySite() # This emulates importing models from a site file. It must come after # widgy_site is defined, because widgy doesn't exist yet without the # site. # We have to be able to import models from the site file to use when # checking compatibility. VersionedWidgyField(site='tests.core_tests.widgy_config.widgy_site') WidgyField(site='tests.core_tests.widgy_config.widgy_site')