diff options
author | lxf <sng@luxagraf.net> | 2022-05-14 16:38:07 -0400 |
---|---|---|
committer | lxf <sng@luxagraf.net> | 2022-05-14 16:38:07 -0400 |
commit | bb3973ffb714c932e9ec6dd6a751228dc71fe1d3 (patch) | |
tree | 6fa32f9392ad2ec32271349b86a4c1388fd6ba95 /app/accounts/models.py |
initial commit
Diffstat (limited to 'app/accounts/models.py')
-rw-r--r-- | app/accounts/models.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/accounts/models.py b/app/accounts/models.py new file mode 100644 index 0000000..feb20bf --- /dev/null +++ b/app/accounts/models.py @@ -0,0 +1,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] |