[Fixed]-How can I edit an object without saved it in Django

1👍

You should avoid saving object and then filling it with data in different view.

Try using generic edit views such as CreateView/EditView or FormView with Django forms (https://docs.djangoproject.com/en/1.9/ref/class-based-views/generic-editing/).

Example:

class ServerCreateView(CreateView):
    form_class = ServerCreateForm
    template_name = 'servers/add.html'

With this, all validation is done automatically.

0👍

Http calls should be stateless. The connection can be dropped any time, which leaves the DB in the same inconsistent state which is what you try to avoid here. Instead of using the form which only contains name, you could just redirect the user to a new page with the form for the rest of the data with the previously entered name as a get parameter, and pre-fill that form with the name on that page

👤fodma1

Leave a comment