Gallery App in Django project

77 views
Skip to first unread message

bradford li

unread,
May 8, 2014, 3:05:06 AM5/8/14
to django...@googlegroups.com
I'm pretty new to Django and I thought, what better way to learn than to create your own website?!

I posted a question on Stackoverflow.


I want to create a Gallery App that would display a list of albums. These albums would have a thumbnail of the first picture. Once the album is clicked, the photos would be displayed on the same url. From what I've learned I think this requires an AJAX request. I'm pretty new to web development. =/ 

I know how to put an image onto a page however categorizing images and giving them properties and also display many of them at once without hard coding is something I have not learned yet. I need a bit of help doing this. I'm not sure of the process or best practices to do so. Any help is much appreciated thank you!!

m1chael

unread,
May 8, 2014, 6:52:59 PM5/8/14
to django...@googlegroups.com
photologue may work for you.. i use it, and have customized it very
extensively for my needs
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e0628382-3eea-44c5-bcb1-2720f36b05b1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Venkatraman S

unread,
May 8, 2014, 9:32:46 PM5/8/14
to django...@googlegroups.com
On Fri, May 9, 2014 at 4:22 AM, m1chael <myk...@gmail.com> wrote:
photologue may work for you.. i use it, and have customized it very
extensively for my needs

+1. Very easy to customize and play with.  Does most of the functions needed of a photo-app.

bradford li

unread,
May 9, 2014, 12:50:59 PM5/9/14
to django...@googlegroups.com
I want to do so without using an app because I feel that way I can really learn Django. Currently this is what I have in my models.py

from django.db import models
from django.contrib import admin
#from PIL import Images as PImage
import os
from PersonalWebsite.settings import MEDIA_ROOT

#def get_upload_file_name(instance, filename):
# return "uploaded_files/%s_%s" % (str(time()).replace('.', '_'), filename)

class Album(models.Model):
title = models.CharField(max_length = 60)

def __unicode__(self):
return self.title

def get_image_by_album(self):
images = []
for root, dirs, files in os.walk(os.path.join(MEDIA_ROOT, 'albums', self.title)):
mypath = os.sep.join(os.path.join(root, file).split(os.sep[4:]))
images.append(mypath)
return images


class Tag(models.Model):
tag = models.CharField(max_length = 50)
def __unicode__(self):
return self.tag

class Image(models.Model):
title = models.CharField(max_length = 60, blank = True, null = True)
#image = models.FileField(upload_to = get_upload_file_name)
tags = models.ManyToManyField(Tag, blank = True)
albums = models.ForeignKey(Album)
width = models.IntegerField(blank = True, null = True)
height = models.IntegerField(blank = True, null = True)
created = models.DateTimeField(auto_now_add=True)


def __unicode__(self):
return self.image.name 

class AlbumAdmin(admin.ModelAdmin):
    search_fields = ["title"]
    list_display = ["title"]

class TagAdmin(admin.ModelAdmin):
    list_display = ["tag"]

class ImageAdmin(admin.ModelAdmin):
    search_fields = ["title"]
    list_display = ["__unicode__", "title", "created"]
    list_filter = ["tags", "albums"]

admin.site.register(Album, AlbumAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Image, ImageAdmin)

I'm not sure if my models.py is set up correctly. But I did the best i can =/ My "get_image_by_album" method walks through all directories in my albums directory to get the path of the image and appends them to a list called "images". That is how much I got done so far. I was thinking about setting up a simple admin interface as well to allow me to easily maintain the site. Not sure where to go from here though =/
Reply all
Reply to author
Forward
0 new messages