I want to implement a wishlist for the products in my Django site so that I can represent them in a wishlist page to the user.
the products are in the products app.
products.models.py
class ControlValves(models.Model):
title = models.CharField(max_length=50, unique=True)
product_name = models.CharField(max_length=50, blank=True)
....
class Accessories(models.Model):
title = models.CharField(max_length=50, unique=True)
description = models.CharField(max_length=50, blank=True)
....
There is a services app that contains various services(models). Then I want to create a wishlist in users app.
users.models.py
class Wishlist(models.Model):
owner = models.ForeignKey( User, on_delete=models.CASCADE)
title = models.CharField(max_length=50, null=True, blank=True)
item = models.ForeignKey( which_model_should_be_here??? , on_delete=models.CASCADE)
since I am fetching the list of products
and services
from two different apps and within each, there are various models:
question:
1- I don't know how to point to the selected product or service? should I declare a foreign key to each possible product model o services model, or there is another efficient way?
2- an example of how to load them to show to the user( i.e. how to write a query to load them from DB) would be great.
I also checked the answer to this and this, but they are fetching products from just one model, so it's easy because there should be just one foreign key.