--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/710931514.1164631.1588692639153%40mail.yahoo.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2041909068.1176186.1588698102511%40mail.yahoo.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjvpcP%2BNsduU4ryeGaatUyU%3D-OPM1R6Wt6WMZz_rBrVWKA%40mail.gmail.com.
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from .models import UserProfile
from django import forms
class SignUpForm(UserCreationForm):
email = forms.EmailField()
first_name = forms.CharField(max_length=100)
last_name = forms.CharField(max_length=100)
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2')
class UserProfileForm(forms.ModelForm):
Photo = forms.FileField( max_length=100) #widget=forms.ClearableFileInput(attrs={'multiple': True}),
dob = forms.DateField(widget=forms.TextInput(attrs={'type': 'date'}))
country = forms.CharField(max_length=100)
State = forms.CharField(max_length=100)
District = forms.CharField(max_length=100)
phone = forms.CharField(max_length=10)
class Meta:
model = UserProfile
fields = ('Photo', 'dob', 'country', 'State', 'District', 'phone')
def userprofileview(request): # Authenticated user filling the form to complete the registration
if request.method == 'POST':
form = UserProfileForm(request.POST, request.FILES)
if form.is_valid():
pr = UserProfile()
pr.user = User.objects.get(id=request.user.id)
pr.dob = form.cleaned_data['dob']
pr.country = form.cleaned_data['country']
pr.State = form.cleaned_data['State']
pr.District = form.cleaned_data['District']
pr.phone = form.cleaned_data['phone']
pr.save()
messages.success(request, f'Profile has been updated successfully')
return redirect('/profile')
else:
messages.error(request, AssertionError)
else:
form = UserProfileForm()
return render(request, 'authenticate\\bolo.html', context={'form': form})
@login_required
def profile_page(request): # Fetching data from DB to show user's complete profile page
data = get_object_or_404(UserProfile, user=request.user)
#data2 = get_object_or_404(User, user=request.user)
data2 = User.objects.get(id = request.user.id)
context = {'data': data, 'data2': data2}
return render(request, 'authenticate\\profile.html', locals())
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/168480630.1356055.1588745545917%40mail.yahoo.com.