From 4974eb58480f413c67f5f6e8fac430186eda2b62 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 29 Nov 2018 16:57:26 -0600 Subject: uploading all recent changes ahead of sys upgrade --- apps/accounts/models.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'apps/accounts/models.py') diff --git a/apps/accounts/models.py b/apps/accounts/models.py index 5ed7634..d000e3e 100644 --- a/apps/accounts/models.py +++ b/apps/accounts/models.py @@ -1,5 +1,8 @@ from django.db import models from django.contrib.auth.models import AbstractUser +from django.utils.functional import cached_property + +from notes.models import Notebook class User(AbstractUser): @@ -10,7 +13,7 @@ class User(AbstractUser): class UserProfile(models.Model): - user = models.OneToOneField(User, on_delete=models.CASCADE) + user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile') photo = models.ImageField(upload_to='profile', null=True, blank=True) website = models.CharField(max_length=300, null=True, blank=True, default='') location = models.CharField(max_length=300, null=True, blank=True, default='') @@ -20,3 +23,7 @@ class UserProfile(models.Model): def __str__(self): return self.user.username + + @cached_property + def get_notebook_list(self): + return Notebook.objects.filter(owner=self.user).select_related()[:8] -- cgit v1.2.3-70-g09d2