7👍
✅
You should be able to use the “instance” kwarg for the instantiation of the form from an existing model if that’s what you need. Example:
context['form'] = self.form_class(self.request.GET, instance=request.user)
👤kdb
1👍
Try to quit the self.request.get
on get_content_data
forms constructors
and use the “object” variable. With that get
you reinitialize the constructor, more in this link.
My code:
context['form'] = self.form_class(instance=self.object)
- Django.template.loaders.app_directories.Loader fails to find the template file
- Django: AttributeError: 'NoneType' object has no attribute 'split'
- Reading multidimensional arrays from a POST request in Django
- Django admin – how to get all registered models in templatetag?
- Django's annotate Count with division returns integer instead of float
1👍
Get rid of the method get, u don’t need to superscribe it. And apply the following changes in place:
class ClientUpdateView(UpdateView):
model = Employee # You can access the user by the profile, but not the
# oposit
form_class = ClientsForm
second_form_class = ClientsUserForm
template_name = 'admin/client_update.html'
# def get(self, request, *args, **kwargs):
# get rid off
def get_context_data(self, **kwargs):
kwargs['active_client'] = True
if 'form' not in kwargs:
kwargs['form'] = self.form_class(instance=self.get_object())
if 'form2' not in kwargs:
kwargst['form2'] = \
self.second_form_class(instance=self.get_object().user)
return super(ClientUpdateView, self).get_context_data(**kwargs)
def post(self, request, *args, **kwargs):
...
- Create a separate app for my REST API or place it inside my working app?
- Why is gunicorn_django not recommended anymore?
- Django long request timeout
Source:stackexchange.com