Django autocomplete light: no input field - python

I've installed "Django autocomplete light" and now following this tutorial: http://django-autocomplete-light.readthedocs.io/en/master/tutorial.html
Here is my code so far:
setting.py
INSTALLED_APPS = [
'dal',
'dal_select2',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.gis',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'directory',
'geopy',
]
models.py
class Company(models.Model):
CATEGORY_CHOICES = (
('P', 'Parrucchiere'),
('Ce', 'Centro estetico'),
)
self_key = models.ForeignKey('self', null=True, blank=True, related_name='related_self_key_models')
city = models.ForeignKey(City, on_delete=models.CASCADE)
name = models.CharField(max_length=200)
address = models.CharField(max_length=255)
telephone = models.CharField(max_length=200)
category = models.CharField(max_length=1, choices=CATEGORY_CHOICES, null=True)
email = models.CharField(max_length=255, null=True, blank=True)
vat = models.CharField(max_length=200, null=True, blank=True)
location = gis_models.PointField(u"longitude/latitude", geography=True, blank=True, null=True)
gis = gis_models.GeoManager()
objects = models.Manager()
slug = AutoSlugField(populate_from='name', null=True)
def __str__(self):
return self.name
views.py
class CompanyAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
if not self.request.user.is_authenticated():
return Company.objects.none()
qs = Company.objects.all()
if self.q:
qs = qs.filter(name__istartswith=self.q)
return qs
forms.py
class AddCompanyForm(forms.ModelForm):
vat = forms.CharField(required=True)
class Meta:
model = Company
fields = ('name','city','address','telephone','email','vat','self_key')
widgets = {
'self_key': autocomplete.ModelSelect2(url='company-autocomplete')
}
def clean_vat(self):
vat = self.cleaned_data['vat']
if Company.objects.filter(vat__iexact=vat).count() > 1:
raise ValidationError("L'attività digitata esiste già...")
return vat
urls.py
url(
r'^company-autocomplete/$',
autocomplete.Select2QuerySetView.as_view(model=Company),
name='company-autocomplete'
),
html
{% extends 'base.html' %}
{% load static %}
{% block title %}
<title>Aggiungi azienda | ebrand directory</title>
{% endblock title %}
{% block upper_content %}
<br style="line-height:25px"/>
<div class="google-card-full" style="width:auto; height:auto; text-align:center;">
<br style="line-height:25px"/>
<h1 class='title'><img style="width:auto; height:auto;" src='{% static "images/new_company.png" %}'> Aggiungi azienda</h1>
<hr/>
<br/>
<form method="post">
{% csrf_token %}
<table class='form-group' style="width:25%; margin:auto;">
{% for field in form.visible_fields %}
<tr>
<th style='text-align:left'>{{ field.label|capfirst }}:</th>
{% if forloop.first %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% endif %}
{{ field.errors.as_ul }}
<td style='text-align:right'>{{ field }}</td>
</tr>
{% endfor %}
</table>
<br/>
<button class="btn btn-raised btn-primary" type="submit"
style="background-color:#1A88B9;">Aggiungi</button>
</form>
<p style="height:5px"/>
<p><b>ATTENZIONE</b>: ebrand<sup>©</sup> si riserva di verificare l'autenticità dei dati<br/>
prima dell'inserimento dell'azienda all'interno del database.</p>
<p style="height:5px"/>
</div>
<h2 style='margin:0px 0px 15px 25px;'>Oppure...</h2>
<div class="google-card-full" style="width:auto; height:auto; text-align:center;">
<br style="line-height:25px"/>
<h1 class='title'><img style="width:auto; height:auto;" src='{% static "images/new_company.png" %}'> Reclama azienda esistente</h1>
<hr/>
<br/>
<form method="post">
{% csrf_token %}
<table class='form-group' style="width:25%; margin:auto;">
{% for field in form.visible_fields %}
<tr>
<th style='text-align:left'>{{ field.label|capfirst }}:</th>
{% if forloop.first %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% endif %}
{{ field.errors.as_ul }}
<td style='text-align:right'>{{ field }}</td>
</tr>
{% endfor %}
</table>
<br/>
<button class="btn btn-raised btn-primary" type="submit"
style="background-color:#1A88B9;">Aggiungi</button>
</form>
<p style="height:5px"/>
</div>
{% endblock %}
{% block middle_content %} {% endblock %}
{% block content %} {% endblock %}
{% block bottom_content %} {% endblock %}
The problem: 'self_key' field is not populated and also I cannot type (is not an input).
I have already looked at this question without result: Django autocomplete light: field not populated

Related

display data of form 1 on form 2 django SessionWizardView

Django SessionWizardView: User fills in form 1 and then, some of the values of the fields in form one are needed to calculate a number. This number must then be displayed on form 2. I don't know how I can grab the data of form 1 and use it to make a calculation and then display it on form 2.
models.py
class CapsProd(models.Model):
production = models.OneToOneField(Productions, on_delete=models.CASCADE, primary_key=True)
amount_of_caps = models.IntegerField()
conc_per_cap = models.FloatField()
conc_per_tab = models.FloatField()
amount_of_weighed_tabs = models.IntegerField()
mass_all_tabs = models.FloatField()
required_mass_powder = models.FloatField()
weighed_mass_powder = models.FloatField()
caps_size = models.FloatField(choices=CHOICES,)
forms.py
class CapsProdForm1(forms.ModelForm):
class Meta:
model = CapsProd
fields = [
'production',
'amount_of_caps',
'conc_per_cap',
'conc_per_tab',
]
class CapsProdForm2(forms.ModelForm):
class Meta:
model = CapsProd
fields = [
'amount_of_weighed_tabs',
'mass_all_tabs',
'required_mass_powder',
'weighed_mass_powder',
'caps_size',
]
urls.py
app_name = 'caps_prod'
urlpatterns = [
path('', views.CapsProdWizardView.as_view([CapsProdForm1, CapsProdForm2]), name="add_new"),
]
views.py
class CapsProdWizardView(SessionWizardView):
template_name = "caps_prod/prod_form.html"
html
{% extends "base.html" %}
{% load django_bootstrap5 %}
{% block body_block %}
<h1>
Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}
</h1>
<form class="custom-form" method="post">
{% csrf_token %}
<!-- {% bootstrap_form form %} -->
{{ wizard.management_form }}
{% if wizard.form.forms %}
{{wizard.form.management_form }}
{% for form in wizard.form.forms %}
{% bootstrap_form form %}
{% endfor %}
{% else %}
{% bootstrap_form wizard.form %}
{% endif %}
{% if wizard.steps.prev %}
<button type="submit" class="btn btn-primary" value="{{ wizard.steps.first }}">First step</button>
<button type="submit" class="btn btn-primary" value="{{ wizard.steps.prev }}">Previous step</button>
{% endif %}
<input type="submit" value="Submit">
</form>
{% endblock %}
Thanks!

Using fields from a aggregated QuerySet in a django template

So I got a QuerySet result from an aggregate function to display in a low-spec eBay clone of mine. But my problem is displaying certain fields in the Django template as I want, for example, I want to display the highest bidder's username and bid. When I call the whole object itself like so {{winner}}, then it displays. But when I try to access its fields like so {{winner.user_id.username}}, I get no output although the QuerySet does execute.
When I try to get a field like so (winner.user_id.username):
When I only call winner:
models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
CATEGORIES = [
('Appliances', 'Appliances'),
('Tech', 'Tech'),
('Gaming', 'Gaming'),
('Fashion', 'Fashion'),
('Sports and Fitness','Sports and Fitness'),
('Other','Other'),
("Hygiene and Medicine","Hygiene and Medicine"),
("Stationery","Stationery"),
('Decor', 'Decor'),
('Furniture','Furniture'),
('Cars and Mechanical Things','Cars and Mechanical Things'),
("Tools","Tools")
]
# Create models here
class User(AbstractUser):
pass
class Auction_Listing(models.Model):
user_id = models.IntegerField(default=1)
list_title = models.CharField(max_length=64)
desc = models.TextField(max_length=600)
img_url = models.URLField(max_length=200, null=True, blank=True)
start_bid = models.IntegerField()
category = models.CharField(choices=CATEGORIES, max_length=35, null=True, blank=True)
active = models.BooleanField(default=True)
def __str__(self):
return f"ID:{self.id}, {self.list_title}: {self.desc}, {self.start_bid} posted by user:{self.user_id} in Category:{self.category}, url:{self.img_url}"
class Bids(models.Model):
user_id = models.ForeignKey('User', on_delete=models.CASCADE)
auctions = models.ForeignKey('Auction_Listing', on_delete=models.CASCADE, default=1,related_name='bidauc')
bid = models.IntegerField()
def __str__(self):
return f"ID:{self.id}, Bid {self.bid} posted by user:{self.user_id} on auction {self.auctions}"
class Auction_Comments(models.Model):
user_id = models.ForeignKey('User', on_delete=models.CASCADE)
comment = models.TextField(max_length=324, default='N/A')
auctions = models.ForeignKey('Auction_Listing', on_delete=models.CASCADE, default=1,related_name='comauc')
def __str__(self):
return f"ID:{self.id}, Comment: {self.comment} posted by user:{self.user_id} on auction {self.auctions}"
class Watchlist(models.Model):
user_id = models.ForeignKey('User', on_delete=models.CASCADE)
auctions = models.ForeignKey('Auction_Listing', on_delete=models.CASCADE, default=1, related_name='watchauc')
def __str__(self):
return f"ID:{self.id}, user:{self.user_id} on auction {self.auctions}"
views.py
def render_listing(request, title):
if request.method == "POST":
form = BidForm(request.POST)
bid = int(request.POST['new_bid'])
listing = Auction_Listing.objects.get(list_title=title)
comments = Auction_Comments.objects.filter(auctions=listing)
if bid <= listing.start_bid:
error = True
else:
error = False
listing.start_bid = bid
listing.save()
new_bid = Bids(user_id=request.user, auctions=listing, bid=bid)
new_bid.save()
return render(request, 'auctions/listing.html', {
"listing": listing,
"form": form,
"comments": comments,
"error": error,
"comform": CommentForm()
})
else:
form = BidForm()
comform = CommentForm()
listing = Auction_Listing.objects.get(list_title=title)
comments = Auction_Comments.objects.filter(auctions=listing)
high_bid = Bids.objects.filter(auctions=listing).aggregate(maximum=Max("bid"))
winner = Bids.objects.filter(auctions=listing, bid=high_bid['maximum'])
print(winner)
return render(request, 'auctions/listing.html', {
"listing": listing,
"form": form,
"comments": comments,
"error": False,
"comform": comform,
"winner": winner
})
template's code:
{% extends "auctions/layout.html" %}
{% load static %}
{% block title %} Listing: {{listing.list_title}} {% endblock %}
{% block body %}
{% if listing.active %}
<h2>{{ listing.list_title }}</h2>
<div class='listing'>
{% if listing.img_url == "" or listing.img_url == None %}
<a href='#'><img src="{% static 'auctions/img404.png' %}" class='img-fluid'></a>
{% else %}
<a href='#'><img src="{{ listing.img_url }}" class="img-fluid" alt='image of {{ listing.list_title }}'></a>
{% endif %}
<p>
{{ listing.desc }}
</p>
<p>
Current Bid: ${{ listing.start_bid }}
</p>
<p>Category: {{ listing.category }}</p>
<p></p>
{% if user.is_authenticated %}
<div class="bid">
<a href='{% url "watch" listing.list_title %}' class='btn btn-primary'>Add to/Remove from Watchlist</a>
{% if listing.user_id == user.id %}
<a href='{% url "close" listing.list_title %}' class='btn btn-primary'>Close Auction</a>
{% endif %}
</div>
<div class="bid">
<h3>Bid:</h3>
<form method="POST" action='{% url "renlist" listing.list_title %}'>
{% csrf_token %}
{{form}}
<button type="submit" class='btn btn-primary'>Make New Bid</button>
{% if error %}
Please enter a bid higher than the current bid.
{% endif %}
</form>
</div>
{% else %}
<p><a href='{% url "register" %}' class='register'>Register</a> to bid on this item and gain access to other features</p>
{% endif %}
</div>
<div class="listing">
<h3>Comments:</h3>
{% if user.is_authenticated %}
<div id='comform'>
<h4>Post a Comment</h4>
<form method="POST" action="{% url 'commentadd' %}">
{% csrf_token %}
{{comform}}
<button type="submit" class="btn btn-primary">Post Comment</a>
</form>
</div>
{% endif %}
<p>
{% for comment in comments %}
<div class="comment">
<h4>{{comment.user_id.username}} posted:</h4>
<p>{{comment.comment}}</p>
</div>
{% empty %}
<h4>No comments as of yet</h4>
{% endfor %}
</p>
</div>
{% else %}
<h2>This auction has been closed</h2>
<div>
<a href='{% url "watch" listing.list_title %}' class='btn btn-primary'>Add to/Remove from Watchlist</a>
</div>
<p>{{winner.user_id.username}}</p>
{% endif %}
{% endblock %}
Thanks in advance for the help!
Kind Regards
PrimeBeat
This will give a QuerySet. You can see in your second image.
A QuerySet represents a collection of objects from your database.
winner = Bids.objects.filter(auctions=listing, bid=high_bid['maximum'])
You need to iterate over that QuerySet, get whatever data you want and show it in your template.
{% for win in winner %}
<p>{{ win.user_id.username }}</p>
{% endfor %}

Error in viewing a product on my django project

Hey guys I get this error thrown up at me when I click a product on my Django project. I assume its a spelling mistake in either my view or models but I cant see anything. I've attach both an image of the error and my code. Any help would be appreciated. apologies if my post does not contain the correct information needed I'm new to coding.
Views
from django.shortcuts import render, get_object_or_404
from .models import Category,Product
def allProdCat(request, category_id=None):
c_page = None
products = None
if category_id != None:
c_page = get_object_or_404(Category, id=category_id)
products = Product.objects.filter(category=c_page, available=True)
else:
products = Product.objects.all().filter(available=True)
return render(request,'shop/category.html',{'category':c_page, 'products':products})
def prod_detail(request,category_id,product_id):
try:
product = Product.objects.get(category_id=category_id,id=product_id)
except Exception as e:
raise e
return render(request,'shop/product.html', {'product':product})
models
import uuid
from django.db import models
from django.urls import reverse
class Category(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False)
name = models.CharField(max_length=250, unique=True)
description = models.TextField(blank=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def get_absolute_url(self):
return reverse('phoneshop:products_by_category', args=[self.id])
def __str__(self):
return self.name
class Product(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False)
name = models.CharField(max_length=250, unique=True)
description = models.TextField(blank=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.ImageField(upload_to='product', blank=True)
stock = models.IntegerField()
available = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True, blank=True, null=True)
updated = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Meta:
ordering = ('name',)
verbose_name = 'product'
verbose_name_plural = 'products'
def get_absolute_url(self):
return reverse('phoneshop:prod_detail', args=[self.category.id, self.id])
def __str__(self):
return self.name
category.html:
{% extends "base.html" %}
{% load static %}
{% block metadescription %}
{% if category %}
{{ category.description|truncatewords:155 }}
{% else %}
Welcome to the cushion store where you can buy comfy and awesome cushions.
{% endif %}
{% endblock %}
{% block title %}
{% if category %}
{{ category.name }} - The Fantastic Electronic ShopnDrop
{% else %}
See our wide range of products including everything from phones to tablets - The Fantastic Electronic ShopnDrop
{% endif %}
{% endblock %}
{% block content %}
<!--Breadcrumb navigation-->
{% if category %}
<div class="row my_row_class">
<div class="mx-auto">
<p>Our Product Collection | {{category.name}}</p>
</div>
</div>
{% endif %}
<div class="mx-auto">
{% if category %}
<img class="my_image" src="{{category.image.url}}" alt="{{category.name}}">
</div>
<br>
<div>
<h1 class="text-center my_title">{{category.name}}</h1>
<p class="text-justify">{{category.description}}</p>
</div>
{% else %}
<img class="my_image my_image_padding" src="{% static 'images/banner.jpg' %}" alt="Our Products Collection">
</div>
<br>
<div>
<h1 class="text-center my_title">Our Products Collection</h1>
<p class="text-justify">Find a phone can be difficult at the best of times. With horrible products and prices its a nightmare
But with our wide range of products, The Fantastic Electronic ShopnDrop, could one be the one stop shop
for you.
</p>
</div>
{% endif %}
<div class="container">
<div class="row mx-auto">
{% for product in products %}
<div class="my bottom margin col-9 col-lg-4 col-sm-12 col-md-4">
<div class="cart text-center" style="min-width: 18rem;">
<img class = "card-img-top my_image"><img src="{{product.image.url}}" alt="{{product.name}}">
<div class="card-body">
<h4>{{product.name}}</h4>
<p>€{{product.price}}</p>
</div>
</div>
</div>
{% endfor %}
</div>
<br>
</div>
{% endblock %}
product.html
{% extends "base.html" %}
{% load static %}
{% block metadescription %}
{{ product.description|truncatewords:155 }}
{% endblock %}
{% block title %}
{{ product.name }} - The Fantastic Electronic ShopnDrop
{% endblock %}
{% block content %}
<div class="row my_prod_row_class">
<div class="mx-auto">
<p>Home | {{product.category}} | {{product.name}}</p>
</div>
<div class="container">
<br>
<div class="row">
<div class="col-12 col-sm-12 col-ml-12 col-lg-6 text-center">
<div style="min-width: 18rem;">
<img src="{{product.image.url}}" alt="{{product.name}}">
</div>
</div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div>
<div>
<h1 class="my_prod_title"></h1>{{product.name}}</h1>
<p>€{{product.price}}</p>
<p class="my_title">Product Description</p>
<p class="text-justify my_prod_text">{{product.description}}</p>
{% if product.stock == 0%}
<p class="text-justify my_prod_text"><b>Out of Stock</b></p>
{% else %}
Add to Cart
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
urls
from django.urls import path
from . import views
app_name ='phoneshop'
urlpatterns = [
path('', views.allProdCat, name ='allProdCat'),
path('<uuid:category_id>/', views.allProdCat, name='products_by_category'),
path('<uuid:cateogry_id>/<uuid:product_id>/', views.prod_detail, name='prod_detail'),
]

Custom Django Form Not Displaying - Using Wagtail

Wagtail Blog Site - Comment Model Form Issues
I'm creating a blog site, using Wagtail, and I've run in to a snag. I've added a Comment Model to my page, which I can add comments through the admin section and they display on the correct posts, but the comment form I've created is not displaying for some reason. Here's my relevant code. Any tips on where I went wrong would be greatly appreciated.
blog/models.py
class BlogPage(Page):
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
#tag manager
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
#get feature image
def main_image(self):
gallery_item = self.gallery_images.first()
if gallery_item:
return gallery_item.image
else:
return None
search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
]
content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('date'),
FieldPanel('tags'),
], heading="Blog information"),
FieldPanel('intro'),
FieldPanel('body'),
InlinePanel('gallery_images', label="Gallery images"),
]
def serve(self, request):
# Get current page
post = self
# Get comment form
form = CommentForm(request.POST or None)
# Check for valid form
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect(request.path)
return render_to_response(self,
{
'post': post,
'form': form,
},
context_instance=RequestContext(request))
class Comment(models.Model):
post = models.ForeignKey(BlogPage, related_name='comments')
author = models.CharField(max_length=250)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
approved_comment = models.BooleanField(default=False)
def approve(self):
self.approved_comment = True
self.save()
def __unicode__(self):
return self.text
def __str__(self):
return self.text
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('author', 'text',)
blog_page.html
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
<div class="section">
<div class="container">
<h1 class="title">{{ page.title }}</h1>
<p class="meta subtitle">{{ page.date }}</p>
{% with page.main_image as main_image %}
{% if main_image %}{% image main_image fill-500x300 %}{% endif %}
{% endwith %}
<p>{{ main_image.caption }}</p>
<div class="hero-body subtitle">{{ page.intro }}</div>
<div class="content">
{{ page.body|richtext }}
{% if page.tags.all.count %}
<div class="tags">
<h3>Tags</h3>
{% for tag in page.tags.all %}
<span class="tag is-primary is-medium is-link"><a style="color: white" href="{% slugurl 'tags' %}?tag={{ tag }}">{{ tag }}</a></span>
{% endfor %}
</div>
{% endif %}
<p>Return to blog archive</p>
<hr>
<br>
<form action="" method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input class="control button is-primary" type='submit' name='submit' value='Add Comment'>
</form>
<br>
<hr>
<div class="section">
{% if page.comments.all.count %}
<h2 class='subtitle'>Comments</h2>
<div class="comments">
{% for comment in page.comments.all %}
{% if comment.approved_comment %}
<div class="comment">
<h5 class="date">{{ comment.created_date }}</h5>
<strong><h3 class="title is-3">{{ comment.author }}</h3></strong>
<h4 class="subtitle is-5">{{ comment.text|linebreaks }}</h4>
<br>
<hr>
</div>
{% endif %}
{% empty %}
<br>
<p>No comments yet...</p>
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
Now I'm getting an error saying:
File "/home/kenneth/development/web/sites/mysite/dynamicsalesops/blog/models.py", line 88, in serve
context_instance=RequestContext(request))
TypeError: render_to_response() got an unexpected keyword argument 'context_instance'
Your view_post function is never used. In Wagtail, rendering pages as HTML is handled by a serve method on the page model itself, not by a separate view function: http://docs.wagtail.io/en/v1.9/reference/pages/theory.html#anatomy-of-a-wagtail-request

How to connect model with the model via Foreign Key in template

I have a gallery (app in django 1.8), to which they are plugged in images. My problem is that create a link to the images in each category. I do not know how to do it on the side of the template and URL addresses are correct.
Models
class Gallery(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
image = ThumbnailerImageField(upload_to='paint/%Y/%m/%d')
class Meta:
verbose_name = "Gallery"
verbose_name_plural = " Galleries"
def __unicode__(self):
return self.title
class Paint(models.Model):
AVAILABLE = "Available"
NOT_AVAILABLE = "Not available"
STATUS_PAINT = (
(AVAILABLE, u"Dostępny"),
(NOT_AVAILABLE, u"Nie dostępny")
)
title = models.CharField(max_length=200)
gallery = models.ForeignKey(Gallery)
paint = ThumbnailerImageField(upload_to='paint/%Y/%m/%d')
price = models.CharField(max_length=50, blank=True, null=True)
status = models.CharField(choices=STATUS_PAINT, default=AVAILABLE, max_length=50)
class Meta:
verbose_name = "Picture"
verbose_name_plural = "Images"
def __unicode__(self):
return self.title
Views
class GalleryView(generic.ListView):
model = Paint
template_name = "www/gallery_list.html"
context_object_name = "gallery"
def get_queryset(self):
return Paint.objects.all()
class GalleryDetailsView(generic.ListView):
model = Gallery
context_object_name = "images"
template_name = "www/gallery_details.html"
urls
urlpatterns = [
url(r'^$', MainPage.as_view(), name='mainpage'),
url(r'^about/$', AboutMe.as_view(), name="about"),
url(r'^gallery/$', GalleryView.as_view(), name="gallery"),
url(r'^gallery1/$', GalleryDetailsView.as_view(), name="gallery_details"),
url(r'^contact/$', contact, name="contact"),
]
Template gallery list - main section
{% extends "base.html" %}
{% load thumbnail %}
{% block content %}
{% for i in images %}
<div class="row">
<div class="col-md-5">
<img src="{{ i.image|thumbnail_url:'avatar1' }}"/>
</div>
<div class="col-md-7">
<h3>{{ i.title }}</h3>
<p>{{ i.description }}</p>
</div>
</div>
<hr>
{% endfor %}
{% endblock %}
{% block content_bottom %}{% endblock content_bottom %}
Template gallery details with images of gallery
{% extends "base.html" %}
{% load thumbnail %}
{% block content %}
<table class="center-table">
<tbody>
{% for image in gallery %}
{% if forloop.counter0|divisibleby:3 %}<tr>{% endif %}
<td style="padding-left:50px;padding-right:50px;color:grey">
<a data-lightbox="roadtrip" href="{{ image.paint.url }}"><img src="{{ image.paint|thumbnail_url:'avatar' }}" class="img-thumbnail img-responsive" /></a><br>
<div style="padding-top:8px;padding-bottom:20px;">
<b>Tytuł:</b> {{ image.title }}<br>
<b>Status: </b>{{ image.status }}<br>
<b>Cena: </b>{{ image.price }}<br>
</div>
</td>
{% if forloop.counter|divisibleby:3 or forloop.last %}</tr>{% endif %}
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block content_bottom %}{% endblock content_bottom %}

Categories

Resources