dfrojas
dfrojas

Reputation: 723

accessing to a field in get_object method django in UpdateView

I need to access to a specified field in a model in an UpdateView and then pass that variable to the 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=)

I have tried with

def get_object(self):
   self.object = self.get_object()
   return get_object_or_404(CreditoPredio,predio_id=self.object.pk)

but im getting:

maximum recursion depth exceeded

urls:

url(r'^update/predio-credito/(?P<predio_id>[-_\w]+)/$', UpdatePredioCreditoView.as_view(),name='updateprediogeneral'),

Sorry for the spanish variables, my client ask it like this.

Upvotes: 0

Views: 964

Answers (1)

Alasdair
Alasdair

Reputation: 309089

It looks like you want to fetch the predio_id from the URL, and use it to fetch the object. You can do that with the following:

def get_object(self):
    return get_object_or_404(CreditoPredio, predio_id=self.kwargs['predio_id'])

Upvotes: 1

Related Questions