Browse Source

implemented a product list view

master
Frederic 11 years ago
parent
commit
e05aabbd54
  1. 32
      cash/templates/cash/product_list.html
  2. 4
      cash/urls.py
  3. 19
      cash/views.py

32
cash/templates/cash/product_list.html

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
{% extends "cash/base.html" %}
{% load url from future %}
{% block content %}
Kategorie:
<ul>
<li {% if not category %}style="font-weight: bold"{% endif %}><a href="{% url 'products' %}">Alle Kategorien</a></li>
{% for c in categories %}
<li {% if c == category %}style="font-weight: bold"{% endif %}><a href="{% url 'products' %}{{c.id}}">{{ c.name }}</a></li>
{% endfor %}
</ul>
<table>
<thead>
<tr><td>Name</td><td>Preis</td><td>Aktionen</td></tr>
</thead>
{% for p in product_list %}
<tr>
<td>{{ p.name }}</td>
<td>{{ p.price }} &euro;</td>
<td>
<a href="{% url 'buy' p.id %}">Kaufen</a>
<a href="{% url 'product' p.id %}">Details</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

4
cash/urls.py

@ -11,5 +11,9 @@ urlpatterns = patterns('', @@ -11,5 +11,9 @@ urlpatterns = patterns('',
url(r'transactions/detailed/$', views.transactions, {'detailed': True},
name='transactions_detailed'),
url(r'products/((?P<category_id>\d+)/)?$', views.products, name='products'),
url(r'^/buy/(?P<product_id>\d+)/$', 'cash.views.overview', name='buy'),
)

19
cash/views.py

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
from django.views import generic
from django.shortcuts import render_to_response
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from cash.models import *
@ -41,5 +41,22 @@ def transactions(request, detailed=False): @@ -41,5 +41,22 @@ def transactions(request, detailed=False):
return render_to_response('cash/transaction_list.html',
context_instance=context)
def products(request, category_id=None):
if category_id is None:
category = None
products = Product.objects.all()
else:
category = get_object_or_404(ProductCategory, id=category_id)
products = Product.objects.filter(category=category)
categories = ProductCategory.objects.all()
context = RequestContext(request, { 'product_list': products,
'category': category,
'categories': categories })
return render_to_response('cash/product_list.html',
context_instance=context)

Loading…
Cancel
Save