S
S
Socrates2018-02-05 14:08:58
Django
Socrates, 2018-02-05 14:08:58

Edit user profile?

Guys, I'm trying to make a page for editing my data, for users.
I do this way: I
created a template, a view.
in the view.py file, I take the form for filling out the profile, which is used during registration, into the variable, and into the variable I enter the data from the model that the current user has.
---view.py

def edit_profile_printing(request):
    editForm = PrintshopProfileForm()
    profilData = PrintShop.objects.filter(user__email=request.user)
    if profilData:
        for person in profilData:
            editForm.country = person.country
    else:
        print("NOT")

    return render(request, 'profile/profile_printing.html', {'editForm':editForm})

but the line editForm.country = person.country doesn't work.
I just want to display not an empty form again, but a previously filled one, for further editing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Segey K., 2018-02-05
@Karmov69

from django.shortcuts import get_object_or_404

def edit_profile_printing(request):
    profil_data = get_object_or_404(PrintShop, user=request.user)
    edit_form = PrintshopProfileForm(instance=profile_data)
    return render(request, 'profile/profile_printing.html', {'editForm':edit_form})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question