Вот вам сео оптимизированая модель для фото галареи.
from django.db import models
from django_attach.models import Attachment
from django.contrib.contenttypes.generic import GenericRelation
from django import forms
from django.core.urlresolvers import reverse
# Create your models here.
class Categories(models.Model):
id_cat = models.AutoField(primary_key=True)
Name_cat = models.CharField(max_length=20)
Text_f_cat = models.CharField(max_length=160,default='Description')
key_words = models.CharField(max_length=160,default='Key words')
def __unicode__(self):
return self.Name_cat
class Album(models.Model):
cat = models.ForeignKey(Categories)
id_alb = models.AutoField(primary_key=True)
full_album = models.CharField(max_length=1500,default='Full text 500-1000 smv')
Text_f_album = models.CharField(max_length=300,default='For the preview')
Title_page = models.CharField(max_length=70)
Title_photo = models.CharField(max_length=60)
Alt_photo = models.CharField(max_length=80)
id_photo_for_thumb = models.IntegerField(default=1)
key_words = models.CharField(max_length=160,default='Key words')
desctiption = models.CharField(max_length=160)
def get_random_photo(self):
try:
return self.photo_set.order_by('?')[0]
except IndexError:
return None
def __unicode__(self):
return '%s %s' % (self.Title_page, self.cat)
class Photo(models.Model):
alb = models.ForeignKey(Album)
Title_f_photo = models.CharField(max_length=80)
Alt_f_photo = models.CharField(max_length=80)
image = models.ImageField(upload_to='media',default='_5q16cjpxm.jpg')
def __unicode__(self):
return self.Title_f_photo