Skip to content

Commit

Permalink
Add the slug field to FAQ questions
Browse files Browse the repository at this point in the history
  • Loading branch information
joahim committed Nov 26, 2021
1 parent ca42d50 commit 788a7d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sledilnik/faq/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FaqResource(ModelResource):
class Meta:
queryset = Faq.objects.all()
fields = ["position", "question", "answer"]
fields = ["position", "slug", "question", "answer"]
cache = SimpleCache(timeout=60, public=True)

def dehydrate(self, bundle):
Expand Down
18 changes: 18 additions & 0 deletions sledilnik/faq/migrations/0009_faq_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.7 on 2021-11-26 18:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('faq', '0008_auto_20211125_1519'),
]

operations = [
migrations.AddField(
model_name='faq',
name='slug',
field=models.SlugField(blank=True, help_text='Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug', max_length=100, null=True, verbose_name='Slug'),
),
]
3 changes: 3 additions & 0 deletions sledilnik/faq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ class Faq(models.Model):
project = models.ForeignKey(Project, verbose_name=_("Project"), on_delete=models.CASCADE, related_name="faqs")
position = models.PositiveIntegerField(_("Position"), default=0, null=False, blank=False)

# slug = models.SlugField(_("Slug"), max_length=100, help_text=_('Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug'))
slug = models.SlugField(_("Slug"), max_length=100, help_text=_('Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug'), null=True, blank=True)
question = models.CharField(_("Question"), max_length=500)
answer = MarkdownField(_("Answer"))

class Meta:
ordering = ["position"]
constraints = [
# models.UniqueConstraint(fields=["project", "slug"], name="unique_slug_per_project"),
models.UniqueConstraint(fields=["project", "question"], name="unique_question_per_project"),
]

Expand Down

0 comments on commit 788a7d1

Please sign in to comment.