Added new models and base templates
This commit is contained in:
parent
50ba30b7ba
commit
8f8a686c3b
|
@ -4,14 +4,14 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# app
|
# app
|
||||||
from .models import Question, TranslatedQuestion
|
from .models import QuestionAnswerCategory, QuestionAnswer
|
||||||
|
|
||||||
|
|
||||||
class TranslatedQuestionInline(admin.TabularInline):
|
class QuestionAnswerInline(admin.TabularInline):
|
||||||
model = TranslatedQuestion
|
model = QuestionAnswer
|
||||||
|
|
||||||
class QuestionAdmin(admin.ModelAdmin):
|
class QuestionAnswerCategoryAdmin(admin.ModelAdmin):
|
||||||
inlines = (TranslatedQuestionInline, )
|
inlines = (QuestionAnswerInline, )
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Question, QuestionAdmin)
|
admin.site.register(QuestionAnswerCategory, QuestionAnswerCategoryAdmin)
|
||||||
|
|
|
@ -11,24 +11,31 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Question',
|
name='QuestionAnswer',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||||
|
('ord', models.PositiveIntegerField(default=1)),
|
||||||
|
('title_es', models.CharField(max_length=256)),
|
||||||
|
('answer_es', models.TextField()),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
},
|
},
|
||||||
bases=(models.Model,),
|
bases=(models.Model,),
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='TranslatedQuestion',
|
name='QuestionAnswerCategory',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||||
('title', models.CharField(max_length=256)),
|
('name_es', models.CharField(max_length=32)),
|
||||||
('answer', models.TextField()),
|
|
||||||
('question', models.ForeignKey(to='faq.Question')),
|
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
},
|
},
|
||||||
bases=(models.Model,),
|
bases=(models.Model,),
|
||||||
),
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='questionanswer',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(to='faq.QuestionAnswerCategory'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models, migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('manga', '0001_initial'),
|
|
||||||
('faq', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='translatedquestion',
|
|
||||||
name='language',
|
|
||||||
field=models.ForeignKey(default=1, to='manga.Language'),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,16 +1,47 @@
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# django
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.translation import get_language, ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class QuestionAnswerCategory(models.Model):
|
||||||
|
name_es = models.CharField(max_length=32)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('name_es', )
|
||||||
|
verbose_name = _('Category')
|
||||||
|
verbose_name_plural = _('Categories')
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
class Question(models.Model):
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.translations.get(language__code='es').title
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return getattr(self, u'name_{}'.format(get_language()), u'')
|
||||||
|
|
||||||
|
|
||||||
class TranslatedQuestion(models.Model):
|
class QuestionAnswer(models.Model):
|
||||||
question = models.ForeignKey(Question, related_name='translations')
|
category = models.ForeignKey(QuestionAnswerCategory,
|
||||||
language = models.ForeignKey('manga.Language')
|
related_name='questions')
|
||||||
title = models.CharField(max_length=256)
|
ord = models.PositiveIntegerField(default=1)
|
||||||
answer = models.TextField()
|
|
||||||
|
# Spanish
|
||||||
|
title_es = models.CharField(max_length=256)
|
||||||
|
answer_es = models.TextField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('ord', )
|
||||||
|
verbose_name = _('Question')
|
||||||
|
verbose_name_plural = _('Questions')
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
@property
|
||||||
|
def title(self):
|
||||||
|
return getattr(self, u'title_{}'.format(get_language()), u'')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def answer(self):
|
||||||
|
return getattr(self, u'answer_{}'.format(get_language()), u'')
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# django
|
||||||
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
|
# app
|
||||||
|
from .views import FaqListView
|
||||||
|
|
||||||
|
urlpatterns = patterns(
|
||||||
|
'',
|
||||||
|
url(r'^$', FaqListView.as_view(), name='faq.list'),
|
||||||
|
)
|
|
@ -1,3 +1,26 @@
|
||||||
from django.shortcuts import render
|
# coding: utf-8
|
||||||
|
|
||||||
# Create your views here.
|
# django
|
||||||
|
from django.views.generic import View
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.shortcuts import render_to_response
|
||||||
|
from django.db.models import Count
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
# shelfzilla.faq
|
||||||
|
from .models import QuestionAnswerCategory
|
||||||
|
|
||||||
|
|
||||||
|
class FaqListView(View):
|
||||||
|
template = 'faq/list.html'
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
data = {
|
||||||
|
'categories': QuestionAnswerCategory.objects.all(),
|
||||||
|
'navigation': {
|
||||||
|
'section': 'faqs',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = RequestContext(request, data)
|
||||||
|
return render_to_response(self.template, context_instance=ctx)
|
||||||
|
|
|
@ -281,6 +281,11 @@ SUIT_CONFIG = {
|
||||||
'label': 'Manga',
|
'label': 'Manga',
|
||||||
'icon': 'icon-book',
|
'icon': 'icon-book',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'app': 'faq',
|
||||||
|
'label': 'FAQs',
|
||||||
|
'icon': 'icon-book',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'label': 'Files',
|
'label': 'Files',
|
||||||
'icon': 'icon-file',
|
'icon': 'icon-file',
|
||||||
|
|
|
@ -41,6 +41,11 @@
|
||||||
<li data-pjax-nav {% if navigation.section == "publishers" %}class="active"{% endif %}>
|
<li data-pjax-nav {% if navigation.section == "publishers" %}class="active"{% endif %}>
|
||||||
<a data-pjax href="{% url 'publishers.list' %}">{% trans "Publishers" %}</a>
|
<a data-pjax href="{% url 'publishers.list' %}">{% trans "Publishers" %}</a>
|
||||||
</li>
|
</li>
|
||||||
|
<!--
|
||||||
|
<li data-pjax-nav {% if navigation.section == "faqs" %}class="active"{% endif %}>
|
||||||
|
<a data-pjax href="{% url 'faq.list' %}">{% trans "Faq" %}</a>
|
||||||
|
</li>
|
||||||
|
-->
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{% extends "_layout.html" %}
|
|
@ -0,0 +1,20 @@
|
||||||
|
{% extends "faq/layout.html" %}
|
||||||
|
|
||||||
|
{% block main_content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>FAQs</h1>
|
||||||
|
{% for cat in categories %}
|
||||||
|
<h3>{{ cat.name }}</h3>
|
||||||
|
<ul class="media-list">
|
||||||
|
{% for item in cat.questions.all %}
|
||||||
|
<li class="media well">
|
||||||
|
<div class="media-body">
|
||||||
|
<h2 class="media-heading">{{ item.title }}</h2>
|
||||||
|
<p>{{ item.answer|linebreaks }}</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -14,6 +14,7 @@ urlpatterns = patterns(
|
||||||
url(r'^$', include('shelfzilla.apps.homepage.urls')),
|
url(r'^$', include('shelfzilla.apps.homepage.urls')),
|
||||||
url(r'^', include('shelfzilla.apps.landing.urls')),
|
url(r'^', include('shelfzilla.apps.landing.urls')),
|
||||||
url(r'^', include('shelfzilla.apps.account.urls')),
|
url(r'^', include('shelfzilla.apps.account.urls')),
|
||||||
|
url(r'^faqs/', include('shelfzilla.apps.faq.urls')),
|
||||||
url(r'^blog/', include('shelfzilla.apps.blog.urls', namespace='blog')),
|
url(r'^blog/', include('shelfzilla.apps.blog.urls', namespace='blog')),
|
||||||
url(r'^series/', include('shelfzilla.apps.manga.urls.series')),
|
url(r'^series/', include('shelfzilla.apps.manga.urls.series')),
|
||||||
url(r'^volumes/', include('shelfzilla.apps.manga.urls.volumes')),
|
url(r'^volumes/', include('shelfzilla.apps.manga.urls.volumes')),
|
||||||
|
|
Reference in New Issue