Commits

Anonymous committed a94e070

added some convenience to templates

  • Participants
  • Parent commits 732a4e1

Comments (0)

Files changed (6)

 Installation
-============
+------------
 
 Install *django-photos* via `pip` from the repository::
 
 Add all apps to your INSTALLED_APPS in your `settings.py`::
 
 	INSTALLED_APPS = (
-	# ...,
-	'photos',
-	'taggit',
-	'pagination',
-	'easy_thumbnails',        
-	# ...,
+		# ...,
+		'photos',
+		'taggit',
+		'pagination',
+		'easy_thumbnails',        
+		# ...,
 	)
 	
 Add `pagination.middleware.PaginationMiddleware` to your MIDDLEWARE_CLASSES and make sure that `django.core.context_processors.request` is in the list of TEMPLATE_CONTEXT_PROCESSORS.
 		(r'^photos/', 'photos.urls'),
 		# ...,
 	)
-	
+	
+For more information read the docs.

File src/photos/models.py

         verbose_name_plural = _('Photos')
         ordering = ('-timestamp_created', )
         
+    @models.permalink
+    def get_absolute_url(self):
+        return ('photo-detail', [self.id])
+        
 class Album(models.Model):
     display = models.BooleanField(_('Display'), default=True, help_text=_('Disable to not display this gallery.'))
     name = models.CharField(_('Name'), max_length=250)   
         verbose_name = _('Album')
         verbose_name_plural = _('Albums')
         ordering = ('-timestamp_created', )
+        
+    @models.permalink
+    def get_absolute_url(self):
+        return ('album-detail', [self.id])

File src/photos/templates/photos/album_detail.html

 {% extends "photos/base.html" %}
+{% load pagination_tags %}
+{% load thumbnail %}
 {% block title %}{{block.super}} - Album{% endblock %}
+
+{% block content %}
+<h1>Album from {{ album.user }}</h1>
+
+{% autopaginate object.photos.all 25  %}
+
+<ul>
+{% for photo in object.photo.all %}
+<li><img src="{% thumbnail photo.photo 150x150 crop quality=50 %}" /></li>
+{% endfor %}
+</ul>
+{% endblock %}

File src/photos/templates/photos/album_list.html

 {% paginate %}
 <ul>
 {% for album in object_list %}
-<li>{{album}}<br />
+<li><a href="{{ album.get_absolute_url }}">{{ album }}</a><br />
 {% for photo in album.photos.all|slice:":3" %}
 <a href="{% url photo-album-detail album.id photo.id %}"><img src="{% thumbnail photo.photo 100x100 crop quality=50 %}" description="{{ photo.description }}" /></a> 
 {% endfor %}

File src/photos/templates/photos/photo_detail.html

 {% block title %}{{block.super}} - Photo{% endblock %}
 {% block content %}
 
+<h1>Photo from {{ object.user }}</h1>
+
 {% if album %}
 {% get_next album object as next %}
 {% get_previous album object as prev %}

File src/photos/templates/photos/photo_list.html

 {% extends "photos/base.html" %}
+{% load pagination_tags %}
+{% load thumbnail %}
+
 {% block title %}{{block.super}} - List of Photos{% endblock %}
+
+{% block content %}
+
+{% if user %}
+<h1>Photos from {{ user }}</h1>
+{% else %}
+<h1>Photos</h1> 
+{% endif %}
+
+{% autopaginate object_list 50 %}
+
+<ul>
+{% for photo in object_list %}
+<li><a href="{{photo.get_absolute_url}}"><img src="{% thumbnail photo.photo 250x250 crop quality=50 %}" /></a></li>
+{% endfor %}
+</ul>
+
+{% endblock %}