модель ---
class UserProfile(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE)
Mobile =models.CharField(max_length=15,default="")
def __str__(self):
return self.user.username
форма ----
class UserProfileForm(forms.ModelForm):
Mobile = forms.CharField(widget=forms.TextInput(attrs={'class' : 'myinput', 'placeholder':'Mobile Number','title':'Please Enter Phone Number Without Country Code, Eg:9999999999 '}),min_length=10, max_length= 15, required =True ,validators = [clean_phone, ])
class Meta:
model = UserProfile
fields=('Mobile',)
def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
self.fields['Mobile'].widget.attrs.update({'class' : 'myinput' ,'placeholder':'Mobile Number','title':'Please Enter Phone Number Without Country Code, Eg:9999999999 '})
просмотр ---
# signup form
def signup (request):
if request.method =="POST":
form = signupForm(request.POST or None)
userprofile =UserProfileForm(request.POST or None)
if form.is_valid() and userprofile.is_valid():
try:
First_Name= form.cleaned_data['Name']
email= form.cleaned_data['email']
password= form.cleaned_data['password']
re_password= form.cleaned_data['re_password']
mobile= userprofile.cleaned_data['Mobile']
print(User.userprofile)
if User.objects.filter(username=email).exists() or User.objects.filter(email=email).exists():
print("Email id is already taken")
elif User.userprofile.objects.filter(mobile=mobile).exsist():
print("Mobile Number already taken ")
Я хотел бы знать, мобильный ли номер уже доступен в профиле пользователя