How to add Formset in this methodology?
I'm trying to make a inline formset where the people who are trying to register can also add his pincodes that he can work. I'm not sure how to make the forms, views and html template for it. The reason being it because I've already made a function in the def so I'm not sure how to add this inline formset also. So Thanks in advance
models.py
class User(AbstractUser):
ADDCHKS_ID=models.CharField(max_length=16, blank=True, null=True)
is_active=models.BooleanField(default=False,blank=True, null=True)
is_excutive=models.BooleanField(default=False,blank=True, null=True)
class ExcutiveRegistration(models.Model):
User = models.ForeignKey(User, on_delete=models.CASCADE,null=True)
'''Personal Details'''
First_name = models.CharField(max_length=100,null=True ,blank=True)
Last_name = models.CharField(max_length=100,null=True ,blank=True)
DOB = models.DateField(max_length=100,null=True ,blank=True)
Fathers_name = models.CharField(max_length=100,null=True ,blank=True)
Contact_number = models.IntegerField(max_length=10,null=True ,blank=True)
Alt_Contact_number = models.IntegerField(max_length=10,null=True ,blank=True)
# Profile_picture=models.ImageField(upload_to='images/', null=True, verbose_name="")
'''Current Addresss'''
Pin_code_c = models.IntegerField(max_length=6,null=True ,blank=True)
State_c = models.CharField(max_length=50,null=True ,blank=True)
District_c = models.CharField(max_length=50,null=True ,blank=True)
Taluk_c = models.CharField(max_length=50,null=True ,blank=True)
Location_c = models.CharField(max_length=100,null=True ,blank=True)
House_no_c = models.IntegerField(max_length=4,null=True ,blank=True)
Street_c = models.CharField(max_length=100,null=True ,blank=True)
class ExcutiveRegistrationPincode(models.Model):
ExcutiveRegistration=models.ForeignKey(ExcutiveRegistration, on_delete=models.CASCADE)
Covering_Pincode=models.IntegerField(max_length=6)
forms.py
class ExcutiveRegistrationform(forms.Form):
First_name = forms.CharField(
label='First_name',
widget=forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'First_name',
'rows':1
})
)
views.py
def test2(request):
form = ExcutiveRegistrationform()
if request.method == 'POST':
form = ExcutiveRegistrationform(request.POST, request.FILES)
if form.is_valid():
user21 = User.objects.create_user(
username=form.data['First_name'],
password=str(random.random()),
)
ExcutiveRegistrationform_data = ExcutiveRegistration.objects.create(
User=user21, First_name=form.data['First_name'],
)
return redirect('/Accounts/Physcial_checks')
context = {'form': form}
return render(request, 'accounts\Registration_Pages\Excutive_Registration.html', context)