Application form with Python and Django

2

I'm starting my studies with Python and Django. After creating several simple CRUDS, I tried to create a more complex form using several classes, but I was not successful.

I want to create a screen for typing orders with the customer information (the customer can be registered along with the order), a list with the sellers and add the products. To add the products I think about creating a modal window that queries the products or a field with autocomplete in the form itself with an add button.

Questions:

  • Is it a good practice to create manual forms and persist the data manually?

  • What is the best way to create a form that has information from various templates (Order, OrderPrice, Product and Vendor)?

I'm using Python 3.5, Django 1.10 on Linux.

Thanks in advance for the help.

    
asked by anonymous 07.03.2017 / 02:36

1 answer

2

I suggest that you use the Django% s API .

I will not go into the merits of how to build a form because it does not seem to me the scope of the question, so I will just emphasize some of the benefits we see:

1. Validators for form and fields

Let Django take care of validations of the data types for you based on the type of field chosen in Forms .

2. Multiple formatting options

You can use methods to display Model as list or text, as well as customize form to further customize your style. You can also iterate field by field to customize your display within the template, such as:

index.html

<html>
<head><title>Meu site</title></head>
<body>
<h1>Aqui vai o meu formulário:</h1>
{% for field in form %}
    <p style="color:red">Campo em vermelho num parágrafo com filter: {{ field|meu_filter_personalizado }}</p>
{% endfor %}
</body>
</html>
    
07.03.2017 / 05:17