Я работаю над проектом, и модели, казалось, работали нормально, пока я не добавил поле обратной связи в модели.Доступ к данным в таблице UserProfile невозможен и возвращает вышеуказанную ошибку.
models.py
Roles = (
('sales', 'SALES'),
('operations', 'OPERATIONS'),
('cashier', 'CASHIER'),
('frontdesk', 'FRONTDESK'),
('client', 'CLIENT'),
)
class UserProfile(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE, default=None, null=True)
role = models.CharField(max_length=50, choices=Roles, default='client')
feedback = models.TextField(default=None, null=True)
def __str__(self):
return self.user.username
просмотр для обратной связи:
@login_required
def feedback(request):
form = FeedbackForm()
if request.method =='POST':
form = FeedbackForm(request.POST)
if form.is_valid():
form = FeedbackForm.save()
return render(request, 'NewApp/feedback.html',{'form':form})
forms.py
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
confirm_password = forms.CharField(widget=forms.PasswordInput())
class Meta():
model = User
fields = ('first_name','last_name','username','email','password')
def clean(self):
cleaned_data = super(UserForm, self).clean()
password = cleaned_data.get("password")
confirm_password = cleaned_data.get("confirm_password")
if password != confirm_password:
raise forms.ValidationError(
"password and confirm_password does not match"
)
class UserProfileInfoForm(forms.ModelForm):
class Meta():
model = UserProfile
fields = ('role',)
class FeedbackForm(forms.ModelForm):
class Meta():
model = UserProfile
fields = ('feedback',)