-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom fafanuka page model
Signed-off-by: MelvinKim <melvin.kimathi@savannahinformatics.com> Signed-off-by: MelvinKim <melobruk1@gmail.com>
- Loading branch information
Showing
5 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 3.2.18 on 2023-03-21 10:21 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtailcore', '0078_referenceindex'), | ||
('common', '0006_auto_20230214_1434'), | ||
('content', '0007_alter_customimage_options'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FafanukaContentItem', | ||
fields=[ | ||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), | ||
('date', models.DateField(help_text='This will be shown to readers as the publication date', verbose_name='Post date')), | ||
('category', models.CharField(choices=[('JUST_CURIOUS', 'Just Curious'), ('TYPE 1', 'Type 1'), ('TYPE 2', 'Type 2'), ('GESTATIONAL', 'Gestational')], max_length=64)), | ||
('english_content', models.CharField(max_length=160)), | ||
('kiswahili_content', models.CharField(max_length=160)), | ||
('organisation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='content_fafanukacontentitem_related', to='common.organisation')), | ||
('program', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='content_fafanukacontentitem_related', to='common.program')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('wagtailcore.page',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from django.db import models | ||
from wagtail.admin.panels import FieldPanel, MultiFieldPanel | ||
from wagtail.api import APIField | ||
from wagtail.models import Page | ||
from wagtail.search import index | ||
|
||
from mycarehub.common.models import Organisation, Program | ||
|
||
|
||
class FafanukaContentItem(Page): | ||
""" | ||
A `FafanukaContentItem` represents the content periodically | ||
sent to Fafanuka subscribers. | ||
""" | ||
|
||
class ItemTypes(models.TextChoices): | ||
GENERAL_TIPS = "GENERAL DIABETES TIPS" | ||
TYPE_1 = "TYPE 1 DIABETES " | ||
TYPE_2 = "TYPE 2 DIABETES " | ||
GESTATIONAL = "GESTATIONAL DIABETES " | ||
|
||
# basic properties that each post has | ||
organisation = models.ForeignKey( | ||
Organisation, | ||
on_delete=models.PROTECT, | ||
null=True, | ||
blank=True, | ||
related_name="%(app_label)s_%(class)s_related", | ||
) | ||
|
||
program = models.ForeignKey( | ||
Program, | ||
on_delete=models.PROTECT, | ||
null=True, | ||
blank=True, | ||
related_name="%(app_label)s_%(class)s_related", | ||
) | ||
|
||
date = models.DateField( | ||
"Post date", | ||
help_text="This will be shown to readers as the publication date", | ||
) | ||
category = models.CharField( | ||
max_length=64, | ||
choices=ItemTypes.choices, | ||
) | ||
english_content = models.CharField( | ||
max_length=160, | ||
) | ||
kiswahili_content = models.CharField( | ||
max_length=160, | ||
) | ||
content_panels = Page.content_panels + [ | ||
MultiFieldPanel( | ||
[ | ||
FieldPanel("date"), | ||
FieldPanel("category"), | ||
], | ||
heading="About", | ||
), | ||
FieldPanel("english_content", classname="full"), | ||
FieldPanel("kiswahili_content", classname="full"), | ||
] | ||
|
||
# these fields determine the content that is indexed for search purposes | ||
search_fields = Page.search_fields + [ | ||
index.SearchField("category"), | ||
index.SearchField("english_content"), | ||
index.SearchField("kiswahili_content"), | ||
] | ||
|
||
# this configuration allows these custom fields to be available over the API | ||
api_fields = [ | ||
APIField("date"), | ||
APIField("category"), | ||
APIField("english_content"), | ||
APIField("kiswahili_content"), | ||
] | ||
|
||
# limit the parent page types | ||
parent_page_type = [ | ||
"content.ContentItemIndexPage", | ||
] | ||
|
||
subpage_types = [] # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters