Я не могу получить доступ к информации из расширенной формы модели. Так как модель была сохранена как наставник, я предполагаю, что доступ к информации из нее будет через что-то вроде
user.mentor.*informationname*
Это то, что у меня есть в моих views.py
class TeacherSignUpView(CreateView):
model = User
form_class = TeacherSignUpForm
template_name = 'registration/signup_form.html'
def get_context_data(self, **kwargs):
kwargs['user_type'] = 'teacher'
return super().get_context_data(**kwargs)
def form_valid(self, form):
user = form.save()
# user.set_password(form.cl)
login(self.request, user)
return redirect('teachers:app-instructor-dashboard')
...
def payment_view(request):
form = MentorPaymentForm()
if request.method == 'POST':
form = MentorPaymentForm(request.POST, request.FILES, instance=request.user)
if form.is_valid():
user,mentor = form.save(commit=False)
return redirect('teachers:payment_view')
else:
form = MentorPaymentForm(instance=request.user)
return render(request, 'classroom/teachers/app-instructor-billing.html', {'form': form})
моделях .py:
class Mentor(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='mentor')
linkedin = models.URLField(max_length=200,null=True,blank=True)
photo = models.ImageField(null=True, blank=True, upload_to='media', default='default.jpg')
address = models.CharField(max_length=500, null=True, blank=True)
invoice_name = models.CharField(max_length=200, null=False, blank=False)
account_num = models.IntegerField(default=1234)
bank_name = models.CharField(max_length=50, null=False)
branch_code = models.IntegerField(default=1234)
def __str__(self):
return "Profile of user {}".format(self.user.username)
и forms.py
class TeacherSignUpForm(UserCreationForm):
email = forms.EmailField(max_length=100)
first_name = forms.CharField(max_length=100)
last_name = forms.CharField(max_length=100)
linkedin = forms.URLField(max_length=200)
address = forms.CharField(max_length=500)
invoice_name = forms.CharField(max_length=200)
account_num = forms.IntegerField()
bank_name = forms.CharField(max_length=50)
branch_code = forms.IntegerField()
class Meta(UserCreationForm.Meta):
model = User
fields = ('email', 'username', 'first_name', 'last_name')
def save(self, commit=True):
self.instance.is_teacher = True
user = super(UserCreationForm, self).save(commit=False)
user.email = self.cleaned_data['email']
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.save()
mentor = Mentor.objects.get_or_create(
user=user,
linkedin=self.cleaned_data['linkedin'],
address=self.cleaned_data['address'],
invoice_name=self.cleaned_data['invoice_name'],
account_num=self.cleaned_data['account_num'],
bank_name=self.cleaned_data['bank_name'],
branch_code=self.cleaned_data['branch_code'],
)
return user
Когда я пытаюсь получить доступ к invoice_name, используя
user.mentor.invoice_name
В шаблоне ничего не появляется