在這個基礎視圖....假設queryset = self.objects.get(user_assigned=pk)
有一個值...我想它將它返回到AccountModify
所以def get_object(self, queryset=None):
可以把它和返回它。眼下def get_object()
不接受它,並返回空白queryset
Django 1.6 UpdateView - 有def dispatch()返回queryset返回
class AccountCreateOrModify(object):
model = Employee
form_class = AccountForm
template_name = 'bot_data/account_modify.html'
success_url = reverse_lazy('home')
class AccountModify(LoginRequiredMixin,
AccountCreateOrModify,
UpdateView):
def dispatch(self, request,
*args, **kwargs):
try:
pk = self.request.user.pk
queryset = self.model.objects.get(user_assigned=pk)
except Employee.DoesNotExist:
return redirect('account_add')
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
else:
handler = self.http_method_not_allowed
return handler(request, queryset)
def get_object(self, queryset=None):
return queryset
什麼是self.objects?你的意思是self.model.objects? – RexE
你爲什麼要做處理程序?爲什麼不直接調用super()類的調度方法? – RexE
對不起,我修復了self.model.objects錯字。我將如何調用super()類的調度方法?我想但不能成功。 – dman