Browse Source

add pictures to the article details page

currency
Andreas Zweili 4 years ago
parent
commit
3b73c67c66
  1. 4
      apache/000-default.conf
  2. 3
      django/didgeridoo/webshop/templates/webshop/article_details.html
  3. 11
      django/didgeridoo/webshop/views.py

4
apache/000-default.conf

@ -13,7 +13,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/
ServerAdmin webmaster@localhost
Alias /media/ /vagrant/django/didgeridoo/media/
Alias /media/ /srv/media/
Alias /static/ /vagrant/django/didgeridoo/static/
<Directory /vagrant/django/didgeridoo/didgeridoo>
@ -23,7 +23,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/
</Directory>
<Directory /vagrant/django/didgeridoo/media>
<Directory /srv/media>
Require all granted
</Directory>

3
django/didgeridoo/webshop/templates/webshop/article_details.html

@ -6,4 +6,7 @@
<p><b>Stock:</b> {{ article.stock }}</p>
<p><b>Status:</b> {{ article.status}}</p>
<p><b>Price:</b> {{ article.price_in_chf }}</p>
{% for picture in picture_list %}
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
{% endfor %}
{% endblock %}

11
django/didgeridoo/webshop/views.py

@ -3,7 +3,12 @@ from django.shortcuts import get_object_or_404, render
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from webshop.models import Article, Category, ArticleStatus, Person, City
from webshop.models import (Article,
Category,
ArticleStatus,
Person,
City,
Picture)
from webshop.forms import RegistrationForm
# Create your views here.
@ -36,8 +41,10 @@ def articles_in_category(request, category_id):
def article_details(request, article_id):
article = get_object_or_404(Article, pk=article_id)
picture_list = Picture.objects.filter(article=article_id)
return render(request, 'webshop/article_details.html',
{'article': article})
{'article': article,
'picture_list': picture_list})
@login_required

Loading…
Cancel
Save