簡體   English   中英

在UpdateView中訪問get_object方法django中的字段

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM