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):
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 =/