From 3ba5675bf3cb6511cb24ac4077ffcf1e600ac627 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 25 Jan 2017 12:22:44 +0000 Subject: [PATCH] Add a many-to-many relation to test models --- .../migrations/0014_event_categories.py | 28 +++++++++++++++++++ wagtail/tests/testapp/models.py | 11 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 wagtail/tests/testapp/migrations/0014_event_categories.py diff --git a/wagtail/tests/testapp/migrations/0014_event_categories.py b/wagtail/tests/testapp/migrations/0014_event_categories.py new file mode 100644 index 0000000000..9394fca777 --- /dev/null +++ b/wagtail/tests/testapp/migrations/0014_event_categories.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-01-24 15:04 +from __future__ import unicode_literals + +from django.db import migrations, models +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('tests', '0013_auto_20161220_1957'), + ] + + operations = [ + migrations.CreateModel( + name='EventCategory', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='Name')), + ], + ), + migrations.AddField( + model_name='eventpage', + name='categories', + field=modelcluster.fields.ParentalManyToManyField(blank=True, to='tests.EventCategory'), + ), + ] diff --git a/wagtail/tests/testapp/models.py b/wagtail/tests/testapp/models.py index f984200e54..bd2b46637b 100644 --- a/wagtail/tests/testapp/models.py +++ b/wagtail/tests/testapp/models.py @@ -14,7 +14,7 @@ from django.shortcuts import render from django.utils.encoding import python_2_unicode_compatible from django.utils.six import text_type from modelcluster.contrib.taggit import ClusterTaggableManager -from modelcluster.fields import ParentalKey +from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.models import ClusterableModel from taggit.managers import TaggableManager from taggit.models import TaggedItemBase @@ -197,6 +197,13 @@ class EventPageSpeaker(Orderable, LinkFields): ] +class EventCategory(models.Model): + name = models.CharField("Name", max_length=255) + + def __str__(self): + return self.name + + class EventPage(Page): date_from = models.DateField("Start date", null=True) date_to = models.DateField( @@ -219,6 +226,7 @@ class EventPage(Page): on_delete=models.SET_NULL, related_name='+' ) + categories = ParentalManyToManyField(EventCategory, blank=True) search_fields = [ index.SearchField('get_audience_display'), @@ -243,6 +251,7 @@ EventPage.content_panels = [ FieldPanel('body', classname="full"), InlinePanel('speakers', label="Speakers"), InlinePanel('related_links', label="Related links"), + FieldPanel('categories'), ] EventPage.promote_panels = [