title: Django: "Product matching query does not exist."?
body: <p>I'm new to programming following along a Udemy Python/Django e-commerce tutorial while creating the cart_update function. I ran into this error below. I used ForeignKey for user in my models. Can someone explain what I'm doing wrong; and how should I be thinking about this kinda of error going forward?</p>
  <p>thanks in advance SO communinty</p>
  <pre><code>DoesNotExist at /cart/update/
  Product matching query does not exist.
  
  /Users/duce/Sites/RENUecommerce/src/carts/views.py, line 20, in cart_update
      product_obj = Product.objects.get(id=product_id) …
  </code></pre>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render, redirect, get_object_or_404
  from django.contrib.auth.models import User
  from inventory.models import Product
  from .models import Cart
  
  
  def cart_update(request):
      product_id = 1
      product_obj = Product.objects.get(id=product_id)
      #product_obj = get_object_or_404(Product, id=product_id)
      
      cart_obj, new_obj = Cart.objects.new_or_get(request)
      cart_obj.products.add(product_obj)
      return redirect('cart:update')
  </code></pre>
  <p>models.py</p>
  <pre><code>import random, os
  from django.db import models
  from django.db.models import Q
  from django.db.backends.base import features
  from django.db.models.fields import SlugField
  from django.contrib.auth.models import User
  from django.db.models.signals import pre_save, post_save
  from django.urls import reverse
  from .utls import unique_slug_generator
  
  class ProductManager(models.Manager):
      def featured(self):
          return self.get_queryset().filter(featured=True)
  
          
      def get_by_id(self, id):
          qs = self.get_queryset().filter(id=id) # Product.objects == self.get.queryset()
          if qs.count() == 1:
              return qs.first()
          return None
  
      def search(self, query):
          lookups = Q(title__icontains=query) | Q(description__icontains=query) |Q(price__icontains=query) |Q(tag__title__icontains=query)
          return self.get_queryset().filter(lookups).distinct()
  
  
  class Product(models.Model):
      title       =models.CharField(max_length=120)
      slug        =models.SlugField(blank=True, unique=True)
      description =models.TextField()
      price       =models.DecimalField(decimal_places=2, max_digits=6, default=0.00)
      image       =models.ImageField(upload_to=upload_image_path, null=True, blank=True)
      featured    =models.BooleanField(default=False)
  
      obj = ProductManager()
      objects = models.Manager()
  
      def __str__(self):
          return self.title
  
      def get_absolute_url(self):
         return &quot;/inventory/{slug}/&quot;.format(slug=self.slug)
  
  </code></pre>
  <p>urls.py</p>
  <pre><code>from django.urls import path, re_path
  
  from .views import(
       cart_home, 
       cart_update,
  )
  
  app_name = 'cart'
  
  urlpatterns = [
      path('', cart_home, name='home'),
      path('update/', cart_update, name='update'),
  ]
  ,,,
  </code></pre>