Automatic filling of Django Template



  • Good afternoon.

    There's a form of user profile. The current user data shall be filled with the screen. How can you do that?

    class Profile(models.Model):
        user = models.OneToOneField(User)
        img = models.ImageField(upload_to='user_pic/', blank=True, verbose_name='аватар')
        phone = models.IntegerField(max_length=10, verbose_name=u'контактный телефон')
    

    class ProfileForm(forms.Form):
    first_name = forms.CharField(label=u'Имя', max_length=30, required=True)
    last_name = forms.CharField(label=u'Фамилия', max_length=30, required=True)
    password = forms.CharField(label=u'Пароль', widget=forms.PasswordInput, min_length=4, required=True)
    email = forms.EmailField(label=u'E-mail', required=True)
    phone = forms.CharField(label=u'Контактный телефон', max_length=10, required=True)
    img = forms.ImageField(label=u'Ваш автар или логотип', required=False)

    @render_to('profile.html')
    def edit_profile(request):
    form = LoginForm()

    {{ form_profile.as_p }}

    I'd like to fill the uniform automatically.
    Thank you!



  • For as long as I've learned, you need to take advantage of model forms. https://docs.djangoproject.com/en/dev/topics/forms/modelforms/ ♪ Using the right form from the model, you will be able to automatically complete the data form from an already existing area:

    form = ProfileForm(instance=user)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2