summaryrefslogtreecommitdiff
path: root/app/accounts/models.py
blob: feb20bfdb83540780569b73c8d2eae516dd1e4fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import AbstractUser
from django.utils.functional import cached_property

from notes.models import Notebook


class User(AbstractUser):
    pass

    class Meta:
        ordering = ['-date_joined']


class UserProfile(models.Model):
    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, blank=True, default='')
    location = models.CharField(max_length=300, blank=True, default='')
    bio = models.CharField(max_length=350, blank=True, default='')
    #default_note_folder = models.ForeignKey('notes.Notebook', null=True, on_delete=models.SET_NULL)
    #default_note_public = models.BooleanField(default=False)

    def __str__(self):
        return self.user.username

    def get_absolute_url(self):
        return reverse("accounts:settings")

    @cached_property
    def get_notebook_list(self):
        return Notebook.objects.filter(owner=self.user).select_related().annotate(note_count=models.Count('note'))[:8]