我有一个模型Order
,
class Order(SmartModel):
SUBMITTED = 1
PROCESSED = 2
DELIVERED = 3
PICKED_UP = 4
CANCELLED = 5
ORDER_STATUSES = ((SUBMITTED,'Submitted'),(PROCESSED,'Processed'),(DELIVERED,'Delivered'),(PICKED_UP,'picked_up'),(CANCELLED,'Cancelled'),
date = models.DateTimeField(auto_now=True,auto_now_add=True)
status = models.IntegerField(choices=ORDER_STATUSES, default=SUBMITTED)
restaurant = models.ForeignKey(Restaurant,null=True,blank=True,default = None,help_text="The restaurant the customer order from")
email = models.EmailField(max_length=50,help_text="Needed as alternative")
mobile = PhoneNumberField(max_length=20,default='+25078######',help_text="Needed to communicate and confirm payment from mobile money")
我按如下方式创建并保存此对象,
def create_order(request,self):
orders = Order()
checkout_form = forms.CheckoutForm(request.POST,instance=orders)
orders = checkout_form.save(commit=False)
anon_user = User.objects.get(id=settings.ANONYMOUS_USER_ID)
orders.created_by = anon_user
orders.modified_by = anon_user
orders.status = Order.SUBMITTED
orders.save()
......
我的管理员看起来像这样,
class OrderCRUDL(SmartCRUDL):
model = Order
permissions = True
actions = ('list','read','create','delete','update')
class List(SmartListView):
fields = ('date','status','billing_name','mobile','email','billing_address','billing_city','restaurant','restaurant.services')
search_fields = ('date',)
我想在管理员中restaurant
查看仅从orders
Web 应用程序的菜单中创建的列表。截至目前,餐厅可以查看应用程序上所有订单的列表。
我怎样才能做到这一点,也欢迎阅读建议。
这是正在使用的代码并出现错误TypeError: object of type 'instancemethod' has no len()
def queryset(self,request):
queryset = self.Order.objects.get_queryset()
current_restaurant = Restaurant.objects.get(id=request.user)
return queryset.filter(restaurant = current_restaurant)