I’m having some trouble understanding “import”
This piece of code works properly. I
from checkout import create_order
# Create your views here.
def checkout(request):
if request.method == 'POST':
create_order(request)
return HttpResponseRedirect('/menu/')
return render_to_response("payment_form.html",locals(), context_instance=RequestContext(request))
but for some reason this code gives me the error: (function’ object has no attribute ‘create_order’ )
import checkout
# Create your views here.
def checkout(request):
if request.method == 'POST':
checkout.create_order(request)
return HttpResponseRedirect('/menu/')
return render_to_response("payment_form.html",locals(), context_instance=RequestContext(request))
shouldn’t it work the same?
this is the create order function
from cart import cart
from models import Order, OrderItem
from django.core import urlresolvers
import urllib
def create_order(request):
order = Order()
order.user = request.user
order.status = Order.SUBMITTED
#have this fix this
order.time = 7
order.save()
# if the order save succeeded
if order.pk:
cart_items = cart.get_cart_items(request)
for ci in cart_items:
# create order item for each cart item
oi = OrderItem()
oi.order = order
oi.quantity = ci.quantity
oi.price = ci.price # now using @property oi.product = ci.product
oi.product = ci.product
oi.save()
# all set, empty cart
cart.empty_cart(request)
# return the new order object
return order
this is an img of my files

Here’s your problem:
Your function has the same name as the module, so this is trying to call a function on the function
checkout: