|
|
- from django.db import models
- from django.contrib.auth.models import User
- from django.utils.translation import gettext as _
- from datetime import date
- from django.template.defaultfilters import truncatechars
-
- # Create your models here.
-
- TYPE_CHOICES = (
- ('pers', _('personal')),
- ('prof', _('professional')),
- ('asso', _('association')),
- )
-
- GENRE_CHOICES = (
- ('m', _('Male')),
- ('f', _('Female'))
- )
-
- SEX_CHOICES = (
- (0, _('exclusively heterosexual')),
- (1, _('Heterosexual predominance')),
- (2, _('Predominantly heterosexual, occasionally homosexual')),
- (3, _('Bisexual without preference')),
- (4, _('Predominantly homosexual, occasionally heterosexual')),
- (5, _('Homosexual predominance')),
- (6, _('exclusively homosexual')),
- )
-
- class Profile(models.Model):
- user = models.OneToOneField(User, on_delete=models.CASCADE)
- first_name = models.CharField( max_length=50, blank=True)
- last_name = models.CharField( max_length=50, blank=True)
- gender = models.CharField(choices=GENRE_CHOICES, max_length=1, default='m')
- birthdate = models.DateField(default=date.today())
- companyname = models.CharField(max_length=200, blank=True)
- bio = models.TextField(default='no bio ...', max_length=300, blank=True)
- avatar = models.OneToOneField(
- "Image",
- null=True,
- blank=True,
- on_delete=models.CASCADE)
- #avatar = models.ImageField(default='avatar.png', upload_to='avatars/', blank=True)
- country = models.CharField( max_length=50, blank=True)
- #friends = models.ManyToManyField(User, default=None, blank=True, related_name='friends')
- #slug = models.SlugField(unique=True, blank=True)
- updated = models.DateTimeField(auto_now=True)
- created = models.DateTimeField(auto_now_add=True)
- type = models.CharField(max_length=4, choices=TYPE_CHOICES)
- tel = models.CharField(max_length=50, blank=True)
- sex = models.IntegerField(choices=SEX_CHOICES, blank=True, null=True)
- activated = models.BooleanField(default=False)
- defaddr = models.ForeignKey('Address', blank=True, null=True, on_delete=models.SET_NULL)
-
- def __str__(self):
- return f'{self.user.username}'
-
- def short_bio(self):
- return truncatechars(self.bio, 50)
-
- class Address(models.Model):
- title = models.CharField(max_length=100)
- street1 = models.CharField(max_length=50)
- street2 = models.CharField(max_length=50, blank=True)
- postalcode = models.CharField(max_length=10)
- city = models.CharField(max_length=100)
- state = models.CharField(max_length=50)
- country = models.CharField(max_length=50)
- owner = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
-
- def __str__(self):
- return f'{self.title}'
-
-
- class Image(models.Model):
- photo = models.ImageField(default='avatar.png', upload_to='avatars/')
- owner = models.ForeignKey(User, on_delete=models.CASCADE)
- description = models.CharField(blank=True, max_length=100)
-
- def __str__(self):
- return str(self.description)
-
- #avatar = models.OneToOneField("Image", on_delete=models.CASCADE)
-
-
|