Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth.models import AbstractUser, PermissionsMixin
- from django.db import models
- from django.utils import timezone
- from django.utils.translation import gettext_lazy as _
- from core.choices import Display_name, Sex
- from stdimage import StdImageField
- from core.utils import PathAndRename, resize_and_autorotate
- from django.conf import settings
- from core.choices import Status
- from django.urls import reverse
- class User(AbstractUser, PermissionsMixin):
- email = models.EmailField(_('Email address'), unique=True)
- display_name = models.CharField(max_length=4, choices=Display_name.choices, default=Display_name.USERNAME, blank=True, null=True)
- date_of_birth = models.DateField(_('Date of birth'), blank=True, null=True)
- sex = models.CharField(max_length=4, choices=Sex.choices, default=Sex.NONE, blank=True, null=True)
- telephone = models.CharField(_('Telephone'), max_length=255, blank=True, null=True)
- mobile_phone = models.CharField(_('Telephone Mobile'), max_length=255, blank=True, null=True)
- address = models.CharField(_('Address'), max_length=255, blank=True, null=True)
- secondary_address = models.CharField(_('Secondary Address'), max_length=255, blank=True, null=True)
- city = models.CharField(_('City'), max_length=255, blank=True, null=True)
- province = models.CharField(_('Province'), max_length=255, blank=True, null=True)
- state = models.CharField(_('State'), max_length=255, null=True, blank=True)
- postal_code = models.CharField(_('Postal code'), max_length=50, blank=True, null=True)
- note = models.TextField(_('Note'), blank=True, null=True)
- date_joined = models.DateTimeField(default=timezone.now)
- USERNAME_FIELD = 'username'
- EMAIL_FIELD = 'email'
- REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
- def __str__(self):
- return f'{self.username}'
- def save(self, *args, **kwargs):
- super(User, self).save(*args, **kwargs)
- class Meta:
- ordering = ('-date_joined',)
- class Photo(models.Model):
- user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
- photo_profile =StdImageField(upload_to=PathAndRename("user_photo/"), delete_orphans=True, render_variations=resize_and_autorotate, blank=True ,
- variations={'thumbnail': (160, 120, True),}
- )
- photo_views = models.BooleanField(default=False)
- likes = models.BigIntegerField(default=0)
- views = models.BigIntegerField(default=0)
- status = models.CharField(max_length=50, choices=Status.choices, default=Status.DRAFT)
- created = models.DateTimeField(_('created'), auto_now_add=True)
- modified = models.DateTimeField(_('modified'), auto_now=True)
- def save(self, *args, **kwargs):
- super().save(*args, **kwargs)
- def __str__(self):
- return self.photo_profile
- def get_absolute_url(self):
- """
- <a href="{{ model.get_absolute_url }}" class="model__title">{{ model.title }}</a>
- """
- return reverse('detail', kwargs={'user': self.user})
- class Meta:
- verbose_name = _("Photo")
- verbose_name_plural = _("All Photo user")
- ordering = ['-created']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement