![](/img/trans.png)
[英]Django DetailView - How to change the get_object to check a field
[英]accessing to a field in get_object method django in UpdateView
我需要在UpdateView中訪問模型中的指定字段,然后將該變量傳遞給url
class UpdatePredioCreditoView(UpdateView):
model = CreditoPredio
form_class = PredioCreditoEditForm
success_url = '/'
template_name = 'predio/edit/credito.html'
def get_object(self):
return get_object_or_404(CreditoPredio,predio_id=)
我嘗試過
def get_object(self):
self.object = self.get_object()
return get_object_or_404(CreditoPredio,predio_id=self.object.pk)
但即時通訊:
超過最大遞歸深度
網址:
url(r'^update/predio-credito/(?P<predio_id>[-_\w]+)/$', UpdatePredioCreditoView.as_view(),name='updateprediogeneral'),
對不起,西班牙變量,我的客戶這樣問。
看起來您想從URL中獲取predio_id
,並使用它來獲取對象。 您可以執行以下操作:
def get_object(self):
return get_object_or_404(CreditoPredio, predio_id=self.kwargs['predio_id'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.