0

My models:

class CartItem(models.Model):
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)
    item_price = models.DecimalField(max_digits=9, decimal_places=2,default=0.00)

class Cart(models.Model):
    items = models.ManyToManyField(CartItem, blank=True)
    total = models.DecimalField(max_digits=9, decimal_places=2,default=0.00)

When I add CartItem instance to a cart and then look at the Cart instance in admin dashboard, I see all the CartItem instances instead of the one's I added to the cart. How do I fix it? That's what I mean:

enter image description here But I only added Dell and Canon instances.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Nikita Tonkoskur
  • 1,440
  • 1
  • 16
  • 28

1 Answers1

0

The selected items are displayed right as highlighted. If you want selected items display in another input, use FilteredSelectMultiple widget as:

forms.ModelMultipleChoiceField(None, widget=FilteredSelectMultiple("Items", False, attrs={'rows':'10'}))

Gang Li
  • 26
  • 2