from django.contrib import admin\r
\r
-from libraries.models import Library\r
+from libraries.models import Library, Catalog\r
\r
\r
-admin.site.register(Library)
\ No newline at end of file
+admin.site.register(Catalog)\r
+admin.site.register(Library)\r
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-05-06 15:42+0200\n"
+"POT-Creation-Date: 2013-05-09 16:09+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
-#: models.py:8
+#: models.py:8 models.py:22
msgid "name"
msgstr "nazwa"
#: models.py:9
+msgid "slug"
+msgstr ""
+
+#: models.py:12
+msgid "catalog"
+msgstr "katalog"
+
+#: models.py:13
+msgid "catalogs"
+msgstr "katalogi"
+
+#: models.py:24
msgid "url"
msgstr "url"
-#: models.py:10
+#: models.py:25
msgid "description"
msgstr "opis"
-#: models.py:13
+#: models.py:28
msgid "library"
msgstr "biblioteka"
-#: models.py:14
+#: models.py:29
msgid "libraries"
msgstr "biblioteki"
--- /dev/null
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Catalog'
+ db.create_table(u'libraries_catalog', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=120)),
+ ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=120)),
+ ))
+ db.send_create_signal(u'libraries', ['Catalog'])
+
+ # Adding field 'Library.catalog'
+ db.add_column(u'libraries_library', 'catalog',
+ self.gf('django.db.models.fields.related.ForeignKey')(default=None, related_name='libraries', on_delete=models.PROTECT, to=orm['libraries.Catalog']),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting model 'Catalog'
+ db.delete_table(u'libraries_catalog')
+
+ # Deleting field 'Library.catalog'
+ db.delete_column(u'libraries_library', 'catalog_id')
+
+
+ models = {
+ u'libraries.catalog': {
+ 'Meta': {'object_name': 'Catalog'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'})
+ },
+ u'libraries.library': {
+ 'Meta': {'object_name': 'Library'},
+ 'catalog': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'libraries'", 'on_delete': 'models.PROTECT', 'to': u"orm['libraries.Catalog']"}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['libraries']
\ No newline at end of file
from django.db import models\r
from django.utils.translation import ugettext_lazy as _\r
\r
+\r
+class Catalog(models.Model):\r
+ """Represents a dictionary of libraries"""\r
+\r
+ name = models.CharField(_('name'), max_length = 120, null = False)\r
+ slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True)\r
+\r
+ class Meta:\r
+ verbose_name = _('catalog')\r
+ verbose_name_plural = _('catalogs')\r
+ \r
+ def __unicode__(self):\r
+ return self.name\r
+ \r
+ \r
class Library(models.Model):\r
"""Represent a single library in the libraries dictionary"""\r
\r
name = models.CharField(_('name'), max_length = 120, blank = True)
+ catalog = models.ForeignKey(Catalog, null = False, related_name = 'libraries', on_delete = models.PROTECT)\r
url = models.CharField(_('url'), max_length = 120, blank = True)
description = models.TextField(_('description'), blank = True)\r
\r
{% block body %}
- <h1>{% trans 'Libraries directory' %}</h1>
+ <h1>{% trans 'Libraries directory' %}: {{ catalog.name }}</h1>
<div class="libraries-list">
- {% for library in libraries %}
+ {% for library in catalog.libraries.all %}
<div class="libraries-list-item">
<div class="libraries-list-item-header"><a href="{{library.url}}">{{library.name}}</a></div>
<div class="libraries-list-item-description">
urlpatterns = patterns('libraries.views',
- url(r'^$', 'main_view', name='libraries_main_view'),
+ url(r'^(?P<slug>[a-zA-Z0-9_-]+)$', 'main_view', name='libraries_main_view'),
)
\ No newline at end of file
from django.shortcuts import render_to_response, get_object_or_404\r
from django.template import RequestContext, Template, TemplateSyntaxError\r
\r
-from libraries.models import Library\r
+from libraries.models import Catalog\r
\r
\r
-def main_view(request):\r
- context = RequestContext(request)
- context['libraries'] = Library.objects.all()\r
-\r
+def main_view(request, slug):\r
+ context = RequestContext(request)\r
+ context['catalog'] = get_object_or_404(Catalog.objects.filter(slug = slug).select_related())\r
return render_to_response('libraries/main_view.html', context_instance = context)
\ No newline at end of file