Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:40:38+00:00 2026-06-17T12:40:38+00:00

I am currently working on an e-commerce web app and decided to use the

  • 0

I am currently working on an e-commerce web app and decided to use the Beginning Django Ecommerce book. I am following the content and implementing it in my own way but i am having some issues with some few functions that are not running.
here are the apps with the files where i think the problem is coming from;
1. cart app models.py:

from django.db import models
from menu_items.models import Item
from smartmin.models import SmartModel
import django.db.models.options as options
options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('augment_quatity','name','price','get_absolute_url','total',)

class OrderItem(SmartModel):
    order_id = models.CharField(max_length=50)
    date_added = models.DateTimeField(auto_now_add=True)
    quantity = models.IntegerField(default=0)
    item = models.ManyToManyField(Item)

    class Meta:
        db_table='order_items'

        def __unicode__(self):
            return "%s" % (self.order_id)

        def total(self):
            return self.quatity *self.item.price
        def name(self):
            return self.item.name
        def price(self):
            return self.item.price
        def get_absolute_url(self):
            return self.item.get_absolute_url()
        # incase user orders same item twice we jus add on the quantity
        def augment_quatity(self, quantity):
            self.quatity = self.quantity + int(quantity)
            self.save

orders.py in the same app:

from cart.models import OrderItem
#from cart.models import order_id
from menu_items.models import Item
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
import decimal
import random

ORDER_ID_SESSION_KEY = 'order_id'

# get the current user's cart id, sets new one if blank
def _order_id(request):
    if request.session.get(ORDER_ID_SESSION_KEY,'') == '':
        request.session[ORDER_ID_SESSION_KEY] = _generate_cart_id
    return request.session[ORDER_ID_SESSION_KEY]
def _generate_cart_id():
    order_id =''
    characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()'
    order_id_length = 100
    for y in range(order_id_length):
        order_id += characters[random.randint(0,len(characters)-1
        )]
    return order_id
# return all items from the current user's order
def get_order_items(request):
    return OrderItem.objects.filter(order_id=_order_id(request))
# add an item to order
def add_to_order(request):  
    postdata = request.POST.copy()
    #get item slug from post data, return blank if empty
#   item_slug = postdata.get('item_slug','')
    #get quantity added, return 1 if empty
    quantity = postdata.get('quantity',1)
    # fetch the item or return  missing page error_message
    i = get_object_or_404(Item,)
    # get items in order
    order_items = get_order_items(request)
    item_in_orders = False
    # check to see if item is already in cart
    for order_item in order_items:
        if order_item.item.id == i.id:
            #update the quantity if found
            order_item.augment_quantity(quantity)
    item_in_order = True
    if not item_in_order:
        # creat and save a new order item
        oi = OrderItem()
        oi.item = i
        oi.quantity = quantity
        oi.order_id = _order_id(request)
        oi.save()

2.live app views.py

def show_order(request):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            order.remove_from_order(request)
        if postdata['submit'] == 'Update':
            order.update_order(request)
    order_items = order.get_order_items(request)
    page_title  = 'F4L order' 
    order_subtotal = order.order_subtotal(request)
    return render_to_response('public/order.html',context_instance=RequestContext(request))

Template where the functionality is not working,

{% extends "base.html" %}
{% block content %}
{% load menu_tags %}
<div style="height:30px">
 {% order_box request %}
</div>
<table summary="Your menu order" id="menu_order">
   <caption>Your F4L Orders</caption>
   <thead>
    <tr>
     <th scope="col">Item</th>
     <th scope="col">Price</th>
     <th scope="col" class="right">Total</th>
    </tr>
   </thead>
   <tfoot>
   <tr>
    <th class="right" colspan="2">
     Order Subtotal:
    </th>
    <th class="right">
    {{order_subtotal}}<span> frw</span>
    </th>
   </tr>
   {% if order_items %}
   <tr>
    <th class="right" colspan="2">
     <a href="/url/to/checkout/">Checkout Now</a>
    </th>
   </tr>
   {% endif %}
   </tfoot>
   <tbody>
    {% if order_items %}
     {% for item in order_items %}
    <tr>
     <td>

       {{ item.name }}

     </td>
     <td>{{ item.price }}<span> frw</span></td>
     <td class="right">
     <form method="post" action="." class="order">
     <label for="quantity">Quantity:</label>
     <input type="text" name="quantity" value="{{ item.quantity }}" id="quantity" size="2" class="quantity" max_length="5" />
     <input type="hidden" name="item_id" value="{{ item.id }}" />
     </td>
     <td>
     <input type="submit" name="submit" value="update"/>
     </form>
     </td>
     <td>
     <form method="post" action="." class="order">
     <input type="hidden" name="item_id" value="{{ item.id }}" />
     </form>
     </td>
     <td>
     <form method="post" action="." class="order">
     <input type="hidden" name="item_id" value="{{ item.id}}" />
     <input type="submit" name="submit" value="Remove" />
     </form>
     </td>
     <td class="right">{{ item.total }}<span> frw</span></td>
    </tr>
     {% endfor %}
     {% else %}
    <tr>
    <td colspan="2" style="height:30px;">
     Your F4L order is empty.
    </td>
    </tr>
    {% endif %}
   </tbody>
</table>
{% endblock %}

Now th problem is, the above template code is a page a user redirects to after submitting a form with the quantity of item he/she is buying but that is not happening. After submitting form with for example 10items,i redirect to this page(above _template_), it loads correctly but does not return the information i submitted.

i do understand that this is alot but i have really need your help and will appreciate any sort of help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:40:40+00:00Added an answer on June 17, 2026 at 12:40 pm

    In show_order view you should pass your variables to template as dictionary:

    ...
    context_dict = {'order_items': order_items, 'order_subtotal': order_subtotal}
    return render_to_response('public/order.html', context_dict, context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a bespoke e commerce Django project. The site works
I'm currently working on developing an e-commerce website and I'm going to use C#,
Im currently working on a mobile web app and am wondering if I should
Currently working on an ASP.NET web app and am starting to realise i'm writing
I'm currently working on an C#/ASP.NET project that will host several differents e-commerce websites,
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
Currently working on a site built in Django and i'm getting an issue when
Currently working on a Spring 2.5 web application, looks as if the business has
I am currently working for a company on a rather big scale e-commerce project
I am currently working on Eclipse using java bindings and i'm automating an e-commerce

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.