From 6ff63f091acca7f9b375f50625f908aba54e2837 Mon Sep 17 00:00:00 2001 From: doubaniux Date: Wed, 17 Feb 2021 17:36:22 +0100 Subject: [PATCH] fix wrong user for Preference creation issue --- users/admin.py | 3 ++- users/models.py | 3 +++ users/views.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/users/admin.py b/users/admin.py index ce48a190..94e66175 100644 --- a/users/admin.py +++ b/users/admin.py @@ -3,4 +3,5 @@ from .models import * admin.site.register(Report) -admin.site.register(User) \ No newline at end of file +admin.site.register(User) +admin.site.register(Preference) \ No newline at end of file diff --git a/users/models.py b/users/models.py index 98b4fc27..ad18bd78 100644 --- a/users/models.py +++ b/users/models.py @@ -53,6 +53,9 @@ class Preference(models.Model): def get_serialized_home_layout(self): return str(self.home_layout).replace("\'","\"") + def __str__(self): + return str(self.user) + class Report(models.Model): submit_user = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='sumbitted_reports', null=True) diff --git a/users/views.py b/users/views.py index 6915d03d..1dcd7417 100644 --- a/users/views.py +++ b/users/views.py @@ -228,7 +228,7 @@ def home(request, id): try: layout = user.preference.get_serialized_home_layout() except ObjectDoesNotExist: - Preference.objects.create(user=request.user) + Preference.objects.create(user=user) layout = user.preference.get_serialized_home_layout() return render(