在我外鍵的出價「應用程序,我使用‘秩序’爲外鍵從‘訂單’應用作爲WSGIRequest」對象有沒有屬性‘user_slug’,而使用模型從多個應用
from orders.models import Order
from sellers.models import SellerCompany
class Bid(models.Model):
user = models.ForeignKey(User)
order = models.ForeignKey(Order)
company = models.ForeignKey(SellerCompany)
bid_price = models.DecimalField(max_digits=10, decimal_places=2)
active = models.BooleanField(default=True)
在我views.py 的訂單應用程序中,我定義投標視圖
def bid(request, order_slug):
if UserType.objects.is_seller(request.user):
form = BidForm(request.POST or None)
if form.is_valid():
new_form = form.save(commit=False)
new_form.user = request.user
new_form.order.slug = order_slug
new_form.company.name = request.company.name
new_form.save()
return render_to_response('bids/bid.html', locals(), context_instance=RequestContext(request))
else:
messages.error(request, 'consumer account can not bid')
return HttpResponseRedirect('/')
在我行
new_form.order.slug = request.order_slug
它顯示了一個錯誤
'WSGIRequest' object has no attribute 'company'
和其他錯誤是
Bid has no order.
我forms.py文件投標型號是
from django import forms
from .models import Bid
class BidForm(forms.ModelForm):
class Meta:
model = Bid
fields = ('bid_price','active')
通過這個練習中,我試圖order_slug分配到的爲了模型蛞蝓場。和公司以的名稱SellerComapny誰是出價。
您的時間n幫助將不勝感激。
你是否正在運行這個通過wsgi?它是一個開發服務器嗎? – Wtower
我在** localhost **/**開發服務器上運行這個** ** – abdullah