因此,我有这个CreateShopView视图,供卖方类型用户简单地注册他们的商店。Shop模型有一个默认设置为“processing”的status字段,而且很明显,我的ShopCreateForm中没有包含这个字段,所以每次卖家注册商店时,它都会以'processing‘的状态保存在数据库中。我的问题是,我怎样才能防止销售商在仍有一间具有“代购”地位的店铺时注册新店铺。提前谢谢。
发布于 2022-01-06 13:01:49
您甚至可能不想让用户进入表单!
在您的view.py中,类似于这些内容的东西应该可以工作:
from django.contrib import messages
def new_shop(request):
shop = Shop.objects.filter(user=request.user).last()
if shop:
if shop.status == 'processing':
messages.add(request, messages.ERROR, 'Your last shop has not been approved yet.')
return redirect('shop:overview') # redirect the user and display error message
# render the form herehttps://stackoverflow.com/questions/70607422
复制相似问题