Answer the question
In order to leave comments, you need to log in
How to add products to "favorites" in django?
I was very tired with this task, I created a small test project especially for the question:
The logic is simple: there is an application for goods, there is an application for favorite products that the user will add on their own.
there is a page with products (created in the database through models and displayed through a template engine):
application model:
from django.db import models
class Product(models.Model):
'''таблица с товарами, имеет только столбик названий товаров'''
name_product = models.CharField('название товара', max_length=50)
def __str__(self):
return self.name_product
from django.shortcuts import render
from .models import Product
def all_product(request):
'''Функция, которая выводит все товары которые у нас имеются'''
all_product = Product.objects.all
context = {
'all_product': all_product,
}
return render(request, 'products/all_products.html', context)
<h1>Товары в наличии:</h1>
{% for i in all_product %}
<p>{{ i }} <a href="/">добавить</a></p>
{% endfor %}
<a href="/favorite_products/">Перейти в любимые товары</a>
Answer the question
In order to leave comments, you need to log in
Isn't it possible to do just that.
Let's say we have a model called <name>
and there we create two fields, post and user which the ego saved and both of them are the primary key. then we make the form, I think you can do it yourself :) and wow.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question