S
S
Sergey Nekrasov2016-03-16 09:41:05
Django
Sergey Nekrasov, 2016-03-16 09:41:05

How is a catalog made with the output of categories / subcategories from the database as links?

I can't figure out how to call the list of objects from the secondary table of the database,
so that by clicking on a category, all records of this category will open
on a new page as links.
views.py:

def crafts(request):

    craft = MasterCategory.objects.all()
    return render(request, 'users/crafts.html', {'crafts': craft})


def master_list(request, ml_id):

    masterlist = User.objects.get(ml_id=ml_id)
    return render(request, 'users/master_list.html', {'masterlist': masterlist})

URLs.py:
url(r'^crafts/$', views.crafts, name='crafts'),
url(r'^crafts/master_list_(?P<ml_id>[0-9]+)/$', views.master_list, name='master_list'),

crafts templates :
{%for craft in crafts%}
<a href='master_list/'>{{craft}}</a> 
    <br>
    <br>
{%endfor%}

I don’t understand how to make it so that when you click on a category, your url opens, for example, instead of master_list / - master_list_1 / - all components of the category with id = 1 from the database would be displayed

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cyber_bober, 2016-03-16
@Cyber_bober

Something like this, just change the data to yours.

<a href="/category/{{category.id}}">{{category.title]}</a>

I
Ilya, 2016-03-16
@nuBacuk

Like so.

<a href='{% url 'master_list' master_list.id %}'> {{ master_list.title }} </a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question