I want to be able to allow my user to add or remove foreign keys on one of my models. The business logic behind this is that there are many unique products that relate to one "product bundle". I want users to create their own product bundles by creating a new bundle object, then adding or removing products as they see fit.
from django.db import models
# Create your models here.
class Product(models.Model):
product_name = models.CharField(max_length=128)
def __str__(self):
return self.product_name
class ProductBundle(models.Model):
bundle_name = models.CharField(max_length=128)
product_dependencies = models.ForeignKey(Product, related_name="add_product",
on_delete=models.CASCADE)
def __str__(self):
return self.bundle_name
Currently its a list with all of the products, which is not the functionality I'm trying to achieve. A lot of posts talk about adding the related_name field to achieve this but for whatever reason it's not working for me