--- /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 field 'Library.slug'
+ db.add_column(u'libraries_library', 'slug',
+ self.gf('django.db.models.fields.SlugField')(max_length=120, unique=True, null=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'Library.slug'
+ db.delete_column(u'libraries_library', 'slug')
+
+
+ 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'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'null': 'True'}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['libraries']
\ No newline at end of file
"""Represent a single library in the libraries dictionary"""\r
\r
name = models.CharField(_('name'), max_length = 120, blank = True)
+ slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True, null = 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
def __unicode__(self):\r
return self.name\r
\r
+ @models.permalink\r
+ def get_absolute_url(self):\r
+ return ('libraries_library_view', [self.catalog.slug, self.slug])
\ No newline at end of file
<div class="libraries-list">
{% 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-header"><a href="{{library.get_absolute_url}}">{{library.name}}</a></div>
<div class="libraries-list-item-description">
- {% autoescape off %}{{library.description}}{% endautoescape%}
+
</div>
</div>
{% endfor %}
--- /dev/null
+{% extends "base.html" %}\r
+{% load i18n %}\r
+\r
+{% block titleextra %}{{ library.name }}{% endblock %}\r
+\r
+\r
+{% block body %}
+ <h1>{{ library.name }}</h1>\r
+ <div class="left-column">
+ <div class="normal-text">
+ <p>Adres strony www: <a href="{{library.url}}">{{library.url}}</a></p>\r
+ {% autoescape off %}{{library.description}}{% endautoescape%}
+ </div>\r
+ </div>\r
+{% endblock %}
\ No newline at end of file
url(r'^$', 'main_view', name='libraries_main_view'),
url(r'^/$', lambda x: HttpResponseRedirect(x.path[:-1])),
url(r'^/(?P<slug>[a-zA-Z0-9_-]+)$', 'catalog_view', name='libraries_catalog_view'),
+ url(r'^/(?P<catalog_slug>[a-zA-Z0-9_-]+)/(?P<slug>[a-zA-Z0-9_-]+)$', 'library_view', name='libraries_library_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 Catalog\r
+from libraries.models import Catalog, Library\r
\r
\r
def main_view(request):\r
def catalog_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/catalog_view.html', context_instance = context)
\ No newline at end of file
+ return render_to_response('libraries/catalog_view.html', context_instance = context)\r
+ \r
+def library_view(request, catalog_slug, slug):\r
+ context = RequestContext(request)\r
+ context['library'] = get_object_or_404(Library.objects.filter(slug = slug).filter(catalog__slug = catalog_slug))\r
+ return render_to_response('libraries/library_view.html', context_instance = context)
\ No newline at end of file