Skip to content

Commit 83768f6

Browse files
committed
Added a desciption filed and display_title field to book categories
1 parent d84936c commit 83768f6

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

forms.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,14 @@ class MonthForm(forms.Form):
132132
class CategoryForm(forms.ModelForm):
133133
class Meta:
134134
model = models.Category
135-
fields = ('name',)
135+
fields = (
136+
'name',
137+
'description',
138+
'display_title',
139+
)
140+
widgets = {
141+
'description': SummernoteWidget,
142+
}
136143

137144
def save(self, commit=True):
138145
save_category = super(CategoryForm, self).save(commit=False)
@@ -141,4 +148,4 @@ def save(self, commit=True):
141148
if commit:
142149
save_category.save()
143150

144-
return save_category
151+
return save_category
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.29 on 2020-11-19 13:19
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('books', '0013_merge_20200929_0901'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='category',
17+
name='description',
18+
field=models.TextField(blank=True, null=True),
19+
),
20+
migrations.AddField(
21+
model_name='category',
22+
name='display_title',
23+
field=models.BooleanField(default=True, help_text='Mark as false if you want to hide the category title.'),
24+
),
25+
]

models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ def cover_images_upload_path(instance, filename):
3333
return os.path.join(path, filename)
3434

3535

36-
3736
class Category(models.Model):
3837
name = models.CharField(max_length=255)
3938
slug = models.SlugField(max_length=255)
39+
description = models.TextField(
40+
null=True,
41+
blank=True,
42+
)
43+
display_title = models.BooleanField(
44+
default=True,
45+
help_text="Mark as false if you want to hide the category title.",
46+
)
4047

4148
class Meta:
4249
ordering = ('slug',)

templates/books/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{% extends "core/base.html" %}
22

3-
{% block title %}Books{% endblock %}
3+
{% block title %}{% if not category %}Published Books{% else %}{{ category.name }}{% endif %}{% endblock %}
44

55
{% block body %}
66
<section class="content">
77
<div class="row">
88
{% if not category %}
9-
<h4>Published Books</h4>
9+
<h4>Published Books</h4>
1010
{% else %}
11-
<h4>Category: {{ category.name }}</h4>
11+
{% if category.display_title %}
12+
<h4>Category: {{ category.name }}</h4>
13+
{% endif %}
14+
{{ category.description|safe }}
1215
<a href="{% url 'books_index' %}" class="button">< Back to All</a>
1316
{% endif %}
1417

0 commit comments

Comments
 (0)