Wednesday, April 29, 2020

Re: How to use ModelChoiceField? I whould like to filter the output from a field form.

hend hend  Не работает, но и ошибку не выдает. Что-то нужно передать в класс формы?
It doesn't work. And it doesn't show an error (

class OrderNewBigPrintView(LoginRequiredMixin, CustomSuccessMessageMixin, CreateView):
    model
= Order
    template_name
= 'new_order_bp.html'
    form_class
= OrderForm
    success_url
= reverse_lazy('orders')
    success_msg
= 'Заказ сохранён'
   
def get_initial(self):
       
self.initial['name_job'] = TypJob.objects.filter(author__id=self.request.user.id)
       
return self.initial.copy()


среда, 29 апреля 2020 г., 9:07:41 UTC+2 пользователь hend hend написал:



class OrderNewBigPrintView(LoginRequiredMixin, CustomSuccessMessageMixin, CreateView):
    model 
= Order
    template_name 
= 'new_order_bp.html'
    form_class 
= OrderForm
    success_url 
= reverse_lazy('orders')
    success_msg 
= 'Ok'

              # get_initial позволяет установить значения полей связанной формы
              def get_initial(self):        
                  self.initial["name_job"] = TypJob.objects.filter(author__id=self.request.user.id)
         # вернуть нужно копию объекта    
                  return self.initial.copy() 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/41269b59-ac29-4f84-8f5f-80525ff98991%40googlegroups.com.

No comments:

Post a Comment