Skip to content

Commit bc59913

Browse files
committed
Add test fixtures for inline child objects
1 parent 39ad453 commit bc59913

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

tests/fixtures/test.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
"body": "Welcome to our site!"
4141
}
4242
},
43+
{
44+
"pk": 1,
45+
"model": "tests.simplepagerelatedlink",
46+
"fields": {
47+
"page": 2,
48+
"link_text": "a boring link",
49+
"url": "http://boring.example.com/"
50+
}
51+
},
4352

4453
{
4554
"pk": 3,
@@ -63,6 +72,15 @@
6372
"body": "Welcome to our site! It's lovely to meet you."
6473
}
6574
},
75+
{
76+
"pk": 2,
77+
"model": "tests.simplepagerelatedlink",
78+
"fields": {
79+
"page": 3,
80+
"link_text": "a lovely link",
81+
"url": "http://lovely.example.com/"
82+
}
83+
},
6684

6785
{
6886
"pk": 4,
@@ -86,6 +104,15 @@
86104
"body": "Oh, it's you. What do you want?"
87105
}
88106
},
107+
{
108+
"pk": 3,
109+
"model": "tests.simplepagerelatedlink",
110+
"fields": {
111+
"page": 4,
112+
"link_text": "an angry link",
113+
"url": "http://angry.example.com/"
114+
}
115+
},
89116

90117
{
91118
"pk": 5,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.11 on 2016-11-09 17:22
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
import modelcluster.fields
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
('tests', '0001_initial'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='SimplePageRelatedLink',
19+
fields=[
20+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
22+
('url', models.URLField()),
23+
('link_text', models.CharField(max_length=255)),
24+
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='related_links', to='tests.SimplePage')),
25+
],
26+
options={
27+
'abstract': False,
28+
'ordering': ['sort_order'],
29+
},
30+
),
31+
]

tests/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from django.db import models
44

5-
from wagtail.wagtailcore.models import Page
5+
from modelcluster.fields import ParentalKey
6+
from wagtail.wagtailcore.models import Page, Orderable
67

78

89
class SimplePage(Page):
@@ -12,3 +13,9 @@ def get_context(self, request):
1213
context = super(SimplePage, self).get_context(request)
1314
context['breadcrumb'] = self.get_ancestors(inclusive=True).filter(depth__gte=request.site.root_page.depth)
1415
return context
16+
17+
18+
class SimplePageRelatedLink(Orderable):
19+
page = ParentalKey(SimplePage, related_name='related_links')
20+
url = models.URLField()
21+
link_text = models.CharField(max_length=255)

tests/templates/tests/simple_page.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,16 @@ <h1>{{ page.title }}</h1>
1111
{% endfor %}
1212
</ul>
1313
<p>{{ page.body }}</p>
14+
15+
{% with page.related_links.all as related_links %}
16+
{% if related_links %}
17+
<h2>Related links</h2>
18+
<ul>
19+
{% for link in related_links %}
20+
<li><a href="{{ link.url }}">{{ link.link_text }}</a></li>
21+
{% endfor %}
22+
</ul>
23+
{% endif %}
24+
{% endwith %}
1425
</body>
1526
</html>

0 commit comments

Comments
 (0)