Django
0
Вклад в тег
class UserSettingsViews(LoginRequiredMixin, View):
"""Отображение и наверное изменение пользовательских настроек оповещения """
def post(self, request, pk):
settings_exist = get_object_or_404(ObjectsOfSurveillance, user_id=pk)
if request.method == 'POST':
settings_form = ChangeSettingsForm(request.POST, instance=settings_exist)
if settings_form.is_valid():
settings_form.save()
messages.success(request, 'Настройки успешно обновлены!')
return render(request, 'main/user_settings_pg.html', {'settings_form': settings_form})
def get(self, request):
settings_exist = get_object_or_404(ObjectsOfSurveillance, user_id=request.user.id)
settings_form = ChangeSettingsForm(instance=settings_exist)
return render(request, 'main/user_settings_pg.html', {'settings_form': settings_form})