Hi,
I am trying to work with different user profiles where the user can link products to there profile to display on a dashboard.
I have created 3 models:
class Product(models.Model):
product_name = models.CharField(max_length=50, blank=False, unique=True)
product_slug = models.CharField(max_length=50, blank=True,null=True)
product_symbol = models.CharField(max_length=50, blank=True,null=True)
product_price = models.FloatField(blank=True,null=True)
def __str__(self):
return str(self.product_name)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.TextField(max_length=500, blank=True)
location = models.CharField(max_length=30, blank=True)
birth_date = models.DateField(null=True, blank=True)
product_list = models.ManyToManyField(Product, blank=True)
website = models.URLField(max_length=50, blank=True)
twitter = models.CharField(max_length=50, blank=True)
meta = models.CharField(max_length=50, blank=True)
def __str__(self):
return str(self.user
class Holding(models.Model):
product_name = models.ForeignKey(Product, on_delete=models.CASCADE)
profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
product_price = models.FloatField(max_length=50, blank=True, null=True)
def __str__(self):
return str(self.product_name)
I’ve manually added a product to the user profile which works, but im trying to show the product price that the user paid from the holding
model
holdings = Holding.objects.get(profile_id=profile.id)
profile = Profile.objects.get(user = request.user)
products = profile.product_list.all()
Is this apprach with the models the correct way? How do i retrieve the holding
data?
Thanks