Mistři v programování na #hovnokod

Python #449

#-----------view:


def catalog(request):
	subcatalog_list = SubCatalog.objects.all().order_by('index')
	objects_list = Object.objects.all().order_by('subcatalog')
	t = loader.get_template('catalog.html')
	c = RequestContext(request, {
    	'subcatalog_list': subcatalog_list,
    	'objects_list': objects_list,
    })
	return HttpResponse(t.render(c))


#-----------template:
		{% if subcatalog_list %}
    		{% for subcatalog in subcatalog_list %}
    			<div class="section_name clear">{{ subcatalog.name }}</div>
				<div class="clear"></div>
				{% if objects_list %}
    				{% for obj in objects_list %}
    					{% if obj.subcatalog.id == subcatalog.id %}
						<div class="section">
							<a class="clear" href="{{ obj.link }}/">{{ obj.name }}</a>
							{% if obj.description %}
							<div class="description">{{ obj.description|safe }}</div>
							{% endif %}
						{% if forloop.counter0|divisibleby:3 %} 
						{% endif %}
	    				{% endif %}
    				{% endfor %}
				{% else %} 
    				<h2>No objects available.</h2>
    			{% endif %}
    		{% endfor %}
    	{% else %}
    		<h1>No subcatalogs available.</h1>
    	{% endif %}


#-------bonus:
<a onclick="window.location = '/create/' + {{ subcatalog.id }} + '/'"></a>

HovnoKod,