У меня есть приложение Django, содержащее базовую модель профиля, которая расширяет модель пользователя с помощью OneToOneField
class Profile(models.Model):
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
)
И это шаблон URL для / updateProfile
path('updateProfile/<pk>', views.UpdateProfileView.as_view(), name='update_profile'),
, который вызывается из панели навигации сайта следующим образом:
<a href="{% url 'update_profile' request.user %}">UpdateProfile</a>
Я использовал класс ModelForm в forms.py следующим образом:
class update_profile_form(forms.ModelForm):
class Meta:
model = Profile
fields = ('phone_number', 'profile_picture')
А в Views.py вызывается следующее представление на основе классов UpdateView:
@method_decorator(login_required, 'dispatch')
class UpdateProfileView(UpdateView):
model = Profile
success_url = reverse_lazy('home')
form_class = update_profile_form
template_name = 'update_profile.html'
# this is where the error occurs
def get_queryset(self):
return Profile.objects.filter(user=self.request.user)
Мой файл urls.py содержит следующие шаблоны:
urlpatterns = [
path('', TemplateView.as_view(template_name='Login/home.html'), name='home'),
path('home/', TemplateView.as_view(template_name='Login/home.html'), name='home'),
path('updateProfile/<pk>', views.UpdateProfileView.as_view(), name='update_profile'),
]
Я не могу определить, какую комбинацию пользовательских полей использовать выше для отображения формы в шаблоне update_profile.html.