R
R
rumak2017-07-18 15:11:52
Django
rumak, 2017-07-18 15:11:52

Django. How to display existing data in form fields?

I must say right away that I am a beginner, so do not hit me if I say something wrong. I'm racking my brains about how to display existing data in the form fields to change them, and I ask for help from those who have already stuffed their fingers on the keyboard. Code attached:
models.py

class List(models.Model):
    first = models.CharField(max_length=50)
    second = models.CharField(max_length=50)
    patronymic = models.CharField(max_length=50)
    birthday = models.DateField()
    phone = models.CharField(max_length=12)

    def __str__(self):
        return self.second, self.first, self.patronymic

forms.py
class ListForm(forms.Form):
    first = forms.CharField(max_length=50)
    second = forms.CharField(max_length=50)
    patronymic = forms.CharField(max_length=50)
    birthday = forms.DateField()
    phone = forms.CharField(max_length=12)

views.py
def edit_me(request):
    about = ListForm
    template = 'job/about_form.html'
    body = {'about': about}
    if request.POST and about.is_valid():
        obj = about.update()
        obj.update()
        return redirect(reverse(edit_me))
    return render(request, template, body)

about_form.html
{% extends 'job/base.html' %}

{% block content %}
    <h1>Редактирование информации о себе</h1>
    <form method="post" action="">
        <label for="first">Имя: </label>
        <input id="first" type="text" name="first" maxlength="100" required />
        <!--<p>Фамилия: {{ about.second }}</p>
        <p>Отчество: {{ about.patronymic }}</p>
        <p>Дата рождения: {{ about.birthday }}</p>
        <p>Номер телефона: {{ about.phone }}</p>-->
    </form>
{% endblock %}

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ramon Yaskal, 2017-07-18
@rumak

https://tutorial.djangogirls.org/en/django_forms/ - at the end Editing a Form ...is it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question