'How to share my list to other user (Django)

Hello guys i'm a begginer in Django and i made a Shopping-list-app from wathing videos on youtube. I can make list in my app and i want to share my list to other user, but i do't know how really do that. I would be happy if someone could help me.

model.py I tried to use models.ManyToManyField but i know don't what should i do in View.py to app the list from a user to other user

from django.db import models
from django.db import models
from django.contrib.auth.models import User


class Liste(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    title = models.CharField(max_length=30, verbose_name = "Titel")
    item1 = models.CharField(max_length=30, blank=True, verbose_name = "1")
    preis1 = models.DecimalField(max_digits=5, decimal_places=2, default = 0, verbose_name = "Preis")
    item2 = models.CharField(max_length=30, blank=True, verbose_name = "2")
    preis2 = models.DecimalField(max_digits=5, decimal_places=2, default = 0, verbose_name = "Preis")
    item3 = models.CharField(max_length=30, blank=True, verbose_name = "3")
    preis3 = models.DecimalField(max_digits=5, decimal_places=2, default = 0, verbose_name = "Preis")
    item4 = models.CharField(max_length=30, blank=True, verbose_name = "4")
    preis4 = models.DecimalField(max_digits=5, decimal_places=2, default = 0, verbose_name = "Preis")
    item5 = models.CharField(max_length=30, blank=True, verbose_name = "5")
    preis5 = models.DecimalField(max_digits=5, decimal_places=2, default = 0, verbose_name = "Preis")

    @property
    def rate(self):
        total = (self.preis1) + (self.preis2) + (self.preis3) + (self.preis4) + (self.preis5)   
        return total

    def __str__(self):    
        return self.title    


class Share(models.Model):
    user = models.ManyToManyField(User)

This is my List

And here i want to send the list to other user



Solution 1:[1]

the logic need some upgrading so you can get to the point you want ,

from django.db import models
from django.db import models
from django.contrib.auth.models import User

class Liste(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    title = models.CharField(max_length=30, verbose_name = "Titel")

class Item(models.Model):
    liste = models.ForeignKey(Liste,on_delete=models.CASCADE)
    item = models.CharField(max_length=30, verbose_name="Title")
    preis = models.DecimalField(max_digits=5, decimal_places=2,default=0,verbose_name="Preis")

Then you can add multiple item to the list and you can use JavaScript to calculate on template the total of each list , and it will have the user selected as you describe

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rakan con