How to work with Updateview and Forms in the template

Asked

Viewed 514 times

0

I’m trying to render a client’s data in the template, but I’d like to do it without using it {{ form.as_p }} or {{ form.as_table }} I would like to know if you have any way of using the id of the clients in question and using inputs in the template instead of "form", I have tried everything here, I know that if I enter the Django shell I can get the id of the form only, but even with the id in hand I cannot make the client to be rendered for editing, the fields appear but blank.

Detail: With Createview this method of getting the form ids worked, but I want the same to happen with Updateview.

Thanks for your attention.

  • Pq vc n wants to use {{ form.as_p }}? Is there any information you do not want to show?

  • So Nathan, what really happens and the following, I want to work with the layout of it but I’m not getting with form.as_p, I’m using bootstrap throughout the project but I’m still today in the layout part, how to work with css on the form.as_p? I have a combobox also in it, and I did not get a favorable result when trying to implement css in it.

  • Well, then the problem is the "presentation" of the data to the user? If yes you can create your own Model Form, instead of just extending from Forms.Modelform you can tell how each data type should be shown and whether it should be hidden.

1 answer

0

If you just want to display a client’s data in a template, you can use Detailview

https://docs.djangoproject.com/en/1.9/ref/class-based-views/generic-display/#detailview

class ClienteDetailView(DetailView):
    model = Cliente
    template_name = 'clientes/detail.html'

The problem of displaying blank fields may be because in your url you have put some other parameter to the id, not pk.

#urls.py
url(r'^(?P<pk>\d+)/editar/$', ClienteUpdateView.as_view(), name='cliente_update'),

#views
class ClienteUpdateView(UpdateView):
    model = Cliente
    form_class = ClienteForm
    template_name = 'clientes/update.html'


#listagem de clientes
...
   <a href="{% url 'clientes:cliente_update' pk=cliente.id %}">Editar</a>
...

https://docs.djangoproject.com/en/1.9/ref/class-based-views/generic-editing/#updateview

Browser other questions tagged

You are not signed in. Login or sign up in order to post.