kopia lustrzana https://github.com/wagtail/wagtail
Add a many-to-many relation to test models
rodzic
49b78dd8a7
commit
3ba5675bf3
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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 = [
|
||||
|
|
Ładowanie…
Reference in New Issue