from django.shortcuts import redirect
from django.urls impot reverse_lazy
# If you want to use the django's messages framework
from django.contrib import messages
class MyCustomView(UpdateProcessView):
def __init__(self, *args, **kwargs):
# Initialize the parents of MycustomView class
super().__init__(self, *args, **kwargs)
# Then override form_valid method
def form_valid(self, form):
# You need to verify is self.model is iterable or not
# If not, you need to find a way to pass your conditions
# with self.model elements
if 'elm1' in self.model:
messages.error(self.request, "Condition 1 is not met")
return redirect(reverse_lazy('my_url1_name'))
elif 'elm2' in self.model:
messages.error(self.request, "Condition 2 is not met")
return redirect(reverse_lazy('my_url2_name'))
messages.success(self.request, "Valid request")
# which will return a HttpResponseRedirect
return super().form_valid()
如果我真的很理解你的问题和你的问题,我想你是在尝试这样的例子:
我认为您可以研究Model的clean方法。您可以这样尝试:
相关问题 更多 >
编程相关推荐