title: Django Choices field to add to cart function
body: <p>I have an app with a choices field for prices. Two of the categories have a Choices field. I tried to get the desired size of the customer by using the <strong>request.POST.get</strong> script on the views.py to get the value of the price, but it's not showing up.</p>
  <p><strong>Views.py</strong></p>
  <pre><code>@login_required      
  def add_to_cart(request, slug):
      item = get_object_or_404(Item, slug=slug)
      order_item, created = OrderItem.objects.get_or_create(
          item=item,
          customer=request.user,
          ordered=False,
          price = request.POST.get('inlineRadioOptions')
      )
      order_qs = Order.objects.filter(customer=request.user, 
                                      ordered=False)
      if order_qs.exists():
          order = order_qs[0]
          if order.items.filter(item__slug=item.slug).exists():
              order_item.price = request.POST.get('inlineRadioOptions')
              order_item.price
              order_item.item_quantity += 1
              order_item.save()
              messages.success(request, 
                               &quot;This item was updated to your cart.&quot;
                               )
          else:
              messages.success(request, 
                               &quot;This item was added to your cart.&quot;
                               )
              order.items.add(order_item)
              order.save()
      else:
          order = Order.objects.create(
              customer=request.user)
          order.items.add(order_item)
          order.save()
          messages.success(request, 
                           &quot;This item was added to your cart.&quot;
                           )
      return redirect(&quot;featured-food&quot;, slug=slug)
  </code></pre>
  <p>On Views.py, I added <strong>price</strong> as a parameter and use the script <strong>request.POST.get('inlineRadioOptions')</strong> to get the value of the selected radio button, but it does not work.</p>
  <p><strong>Models.py</strong></p>
  <pre><code>class Item(models.Model):
      name = models.CharField(max_length=50)
      categories = models.CharField(choices=CATEGORY_CHOICES, max_length=50)
      sizes = models.CharField(choices=SIZES_CHOICES, max_length=50, null=True, blank=True)
      cake_size = models.CharField(choices=CAKE_CHOICES, max_length=50, null=True, blank=True)
      img = models.ImageField(upload_to=get_upload_path, null=True, blank=True)
      description = models.TextField()
      beverage_s_price = models.FloatField(null=True, blank=True)
      beverage_t_price = models.FloatField(null=True, blank=True)
      beverage_g_price = models.FloatField(null=True, blank=True)
      beverage_v_price = models.FloatField(null=True, blank=True)
      cake_slice_price = models.FloatField(null=True, blank=True)
      cake_whole_price = models.FloatField(null=True, blank=True)
      price = models.FloatField(default=0, null=True, blank=True)
      available = models.BooleanField(default=True)
      slug= models.SlugField(null=True, blank=True)
      
      def __str__(self):
          return str(self.name)
      
      def get_absolute_url(self):
          return reverse(&quot;featured-food&quot;, 
                         kwargs={&quot;slug&quot;: self.slug})
      
      def get_add_to_cart_url(self):
          return reverse(&quot;add-to-cart&quot;, kwargs={
              'slug': self.slug
          })
      
      def get_remove_from_cart_url(self):
          return reverse(&quot;remove-from-cart&quot;, kwargs={
              'slug': self.slug
          })
          
      def get_add_to_cart_store_page_url(self):
          return reverse(&quot;add-to-cart-store-page&quot;, kwargs={
              'slug': self.slug
          })
      
      def get_remove_from_cart_store_page_url(self):
          return reverse(&quot;remove-from-cart-store-page&quot;, kwargs={
              'slug': self.slug
          })
      
      def save(self, *args, **kwargs):
          self.slug = slugify(self.name)
          super(Item, self).save(*args, **kwargs)
          
  
  class OrderItem(models.Model):
      customer = models.ForeignKey(User, on_delete=models.CASCADE)
      item = models.ForeignKey(Item, on_delete=models.CASCADE)
      item_quantity = models.IntegerField(default=1)
      price = models.FloatField(default=0,null=True, blank=True)
      ordered = models.BooleanField(default=False)
      
      def __str__(self):
          return f&quot;{self.item_quantity} of {self.item}&quot;
  </code></pre>
  <p><strong>Store.html</strong></p>
  <pre><code>&lt;div class=&quot;container my-5&quot;&gt;
      &lt;h1 class=&quot;mb-3&quot;&gt;&lt;strong&gt;Beverages&lt;/strong&gt;&lt;/h1&gt;
      &lt;hr&gt;
      &lt;div class=&quot;row&quot;&gt;
          {% for obj in object_list %}
              {% if obj.categories == &quot;Beverage&quot; %}
                  &lt;div class=&quot;col-lg-3 col-md-6 my-3 justify-content-center&quot;&gt;
                      &lt;img src=&quot;{{ obj.img.url }}&quot; alt=&quot;&quot;&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-lg-8 col-md-5 my-4 px-5&quot;&gt;
                      &lt;h4&gt;&lt;strong&gt;{{obj.name}}&lt;/strong&gt;&lt;/h4&gt;
                      &lt;p&gt;{{obj.description|truncatechars:200}}&lt;/p&gt;
                      {% if obj.categories == &quot;Beverage&quot; %}
                      &lt;form method=&quot;POST&quot; action=&quot;{{ obj.get_add_to_cart_store_page_url }}&quot;&gt;
                        {% csrf_token %}
                      &lt;div class=&quot;form-check form-check-inline&quot;&gt;
                          &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;inlineRadioOptions&quot; id=&quot;inlineRadio1&quot; value=&quot;{{obj.beverage_s_price}}&quot; checked&gt;
                          &lt;label class=&quot;form-check-label&quot; for=&quot;inlineRadio1&quot;&gt;&lt;strong&gt;Small &lt;/strong&gt;₱ {{obj.beverage_s_price|floatformat:2 }}&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;form-check form-check-inline&quot;&gt;
                          &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;inlineRadioOptions&quot; id=&quot;inlineRadio2&quot; value=&quot;{{obj.beverage_t_price}&quot;&gt;
                          &lt;label class=&quot;form-check-label&quot; for=&quot;inlineRadio2&quot;&gt;&lt;strong&gt;Tall &lt;/strong&gt;₱ {{obj.beverage_t_price|floatformat:2 }}&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;form-check form-check-inline&quot;&gt;
                          &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;inlineRadioOptions&quot; id=&quot;inlineRadio3&quot; value=&quot;{{obj.beverage_g_price}}&quot;&gt;
                          &lt;label class=&quot;form-check-label&quot; for=&quot;inlineRadio3&quot;&gt;&lt;strong&gt;Grande &lt;/strong&gt;₱ {{obj.beverage_g_price|floatformat:2 }}&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;form-check form-check-inline&quot;&gt;
                          &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;inlineRadioOptions&quot; id=&quot;inlineRadio4&quot; value=&quot;{{obj.beverage_v_price}}&quot;&gt;
                          &lt;label class=&quot;form-check-label&quot; for=&quot;inlineRadio4&quot;&gt;&lt;strong&gt;Venti &lt;/strong&gt;₱ {{obj.beverage_v_price|floatformat:2 }}&lt;/label&gt;
                        &lt;/div&gt;
                        
                        {% endif %}
                        {% if obj.categories == &quot;Cake&quot; %}
                        &lt;div class=&quot;form-check form-check-inline&quot;&gt;
                          &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;inlineRadioOptions&quot; id=&quot;inlineRadio5&quot; value=&quot;{{obj.cake_slice_price}}&quot;&gt;
                          &lt;label class=&quot;form-check-label&quot; for=&quot;inlineRadio5&quot;&gt;&lt;strong&gt;Slice &lt;/strong&gt;₱ {{obj.cake_slice_price|floatformat:2 }}&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;form-check form-check-inline&quot;&gt;
                          &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;inlineRadioOptions&quot; id=&quot;inlineRadio6&quot; value=&quot;{{obj.cake_whole_price}}&quot;&gt;
                          &lt;label class=&quot;form-check-label&quot; for=&quot;inlineRadio6&quot;&gt;&lt;strong&gt;Whole &lt;/strong&gt;₱ {{obj.cake_whole_price|floatformat:2 }}&lt;/label&gt;
                        &lt;/div&gt;
                        {% endif %}
                        {% if obj.categories != &quot;Beverage&quot; and obj.categories != &quot;Cake&quot; %}
                        &lt;div class=&quot;&quot;&gt;
                          &lt;h6&gt;₱ {{obj.price}}&lt;/h6&gt;
                        &lt;/div&gt;
                        {% endif %}
                        &lt;div class=&quot;mt-2&quot;&gt;
                          &lt;small class=&quot;ml-5&quot;&gt;Add to cart&lt;/small&gt;
                          &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary btn-md my-0 p&quot;&gt;&lt;i class=&quot;fas fa-plus&quot;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/button&gt;
                          &lt;a href=&quot;{{ obj.get_remove_from_cart_store_page_url }}&quot; class=&quot;btn btn-danger btn-md my-0 p&quot;&gt;
                            &lt;i class=&quot;fas fa-minus&quot;&gt;&lt;/i&gt;&lt;/a&gt;
                        &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
                  &lt;hr&gt;
              {% endif %}
          {% endfor %}
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>