Answer the question
In order to leave comments, you need to log in
How can you implement a gallery?
There is a gallery model
class Album(models.Model):
title = models.CharField(max_length=255)
caption = models.CharField(max_length=1000)
class Image(models.Model):
image = models.ImageField(upload_to='albums/')
title = models.CharField(max_length=255)
caption = models.CharField(max_length=1000)
album = models.ForeignKey(Album)
Answer the question
In order to leave comments, you need to log in
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
from django.shortcuts import render
from django.http import HttpResponse
from django.db import models
from adst.models import Album
from adst.models import Categories
from adst.models import Photo
# Create your views here.
def index(request):
categir = Categories.objects.all()
context = {'categor': categir}
return render(request,'adst/base.html',context)
def gallary(request,alb_id):
get_photos = Photo.objects.all().filter(alb=alb_id)
categir = Categories.objects.all()
show_albums = Album.objects.all().filter(id_alb=alb_id)
bottom = Album.objects.order_by('cat')[0:4]
context = {'phot':get_photos,'categor': categir,'alb_opis':show_albums,'bottom':bottom}
return render(request,'adst/galar.html',context)
def alboms(request,cat_id):
show_albums = Album.objects.all().filter(cat=cat_id)
categir = Categories.objects.all()
na_ca = Categories.objects.all().get(id_cat=cat_id)
context = {'albom': show_albums,'categor': categir,'na_ca':na_ca}
return render(request,'adst/albums.html',context)
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib.staticfiles import *
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
# Examples:
url(r'^$', 'adst.views.index', name='home'),
# url(r'^blast/', 'adst.views.testes', name='blast'),
url(r'^watch/(?P<alb_id>\d+)$', 'adst.views.gallary', name='Watch'),
# url(r'^albums/', 'adst.views.tisc', name='Alb'),
url(r'^category/(?P<cat_id>\d+)$', 'adst.views.alboms', name='Albom'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question