fmartingr
/
shelfzilla
Archived
1
0
Fork 0

Added new models and base templates

This commit is contained in:
Felipe Martín 2015-04-13 13:33:40 +00:00
parent 50ba30b7ba
commit 8f8a686c3b
11 changed files with 127 additions and 43 deletions

View File

@ -4,14 +4,14 @@
from django.contrib import admin
# app
from .models import Question, TranslatedQuestion
from .models import QuestionAnswerCategory, QuestionAnswer
class TranslatedQuestionInline(admin.TabularInline):
model = TranslatedQuestion
class QuestionAnswerInline(admin.TabularInline):
model = QuestionAnswer
class QuestionAdmin(admin.ModelAdmin):
inlines = (TranslatedQuestionInline, )
class QuestionAnswerCategoryAdmin(admin.ModelAdmin):
inlines = (QuestionAnswerInline, )
admin.site.register(Question, QuestionAdmin)
admin.site.register(QuestionAnswerCategory, QuestionAnswerCategoryAdmin)

View File

@ -11,24 +11,31 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='Question',
name='QuestionAnswer',
fields=[
('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={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='TranslatedQuestion',
name='QuestionAnswerCategory',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=256)),
('answer', models.TextField()),
('question', models.ForeignKey(to='faq.Question')),
('name_es', models.CharField(max_length=32)),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='questionanswer',
name='category',
field=models.ForeignKey(to='faq.QuestionAnswerCategory'),
preserve_default=True,
),
]

View File

@ -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,
),
]

View File

@ -1,16 +1,47 @@
# coding: utf-8
# django
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):
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):
question = models.ForeignKey(Question, related_name='translations')
language = models.ForeignKey('manga.Language')
title = models.CharField(max_length=256)
answer = models.TextField()
class QuestionAnswer(models.Model):
category = models.ForeignKey(QuestionAnswerCategory,
related_name='questions')
ord = models.PositiveIntegerField(default=1)
# 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):
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'')

View File

@ -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'),
)

View File

@ -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)

View File

@ -281,6 +281,11 @@ SUIT_CONFIG = {
'label': 'Manga',
'icon': 'icon-book',
},
{
'app': 'faq',
'label': 'FAQs',
'icon': 'icon-book',
},
{
'label': 'Files',
'icon': 'icon-file',

View File

@ -41,6 +41,11 @@
<li data-pjax-nav {% if navigation.section == "publishers" %}class="active"{% endif %}>
<a data-pjax href="{% url 'publishers.list' %}">{% trans "Publishers" %}</a>
</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 class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}

View File

@ -0,0 +1 @@
{% extends "_layout.html" %}

View File

@ -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 %}

View File

@ -14,6 +14,7 @@ urlpatterns = patterns(
url(r'^$', include('shelfzilla.apps.homepage.urls')),
url(r'^', include('shelfzilla.apps.landing.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'^series/', include('shelfzilla.apps.manga.urls.series')),
url(r'^volumes/', include('shelfzilla.apps.manga.urls.volumes')),