You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.1 KiB

  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. from django.utils.translation import gettext as _
  4. from datetime import date
  5. from django.template.defaultfilters import truncatechars
  6. # Create your models here.
  7. TYPE_CHOICES = (
  8. ('pers', _('personal')),
  9. ('prof', _('professional')),
  10. ('asso', _('association')),
  11. )
  12. GENRE_CHOICES = (
  13. ('m', _('Male')),
  14. ('f', _('Female'))
  15. )
  16. SEX_CHOICES = (
  17. (0, _('exclusively heterosexual')),
  18. (1, _('Heterosexual predominance')),
  19. (2, _('Predominantly heterosexual, occasionally homosexual')),
  20. (3, _('Bisexual without preference')),
  21. (4, _('Predominantly homosexual, occasionally heterosexual')),
  22. (5, _('Homosexual predominance')),
  23. (6, _('exclusively homosexual')),
  24. )
  25. class Profile(models.Model):
  26. user = models.OneToOneField(User, on_delete=models.CASCADE)
  27. first_name = models.CharField( max_length=50, blank=True)
  28. last_name = models.CharField( max_length=50, blank=True)
  29. gender = models.CharField(choices=GENRE_CHOICES, max_length=1, default='m')
  30. birthdate = models.DateField(default=date.today())
  31. companyname = models.CharField(max_length=200, blank=True)
  32. bio = models.TextField(default='no bio ...', max_length=300, blank=True)
  33. avatar = models.OneToOneField(
  34. "Image",
  35. null=True,
  36. blank=True,
  37. on_delete=models.CASCADE)
  38. #avatar = models.ImageField(default='avatar.png', upload_to='avatars/', blank=True)
  39. country = models.CharField( max_length=50, blank=True)
  40. #friends = models.ManyToManyField(User, default=None, blank=True, related_name='friends')
  41. #slug = models.SlugField(unique=True, blank=True)
  42. updated = models.DateTimeField(auto_now=True)
  43. created = models.DateTimeField(auto_now_add=True)
  44. type = models.CharField(max_length=4, choices=TYPE_CHOICES)
  45. tel = models.CharField(max_length=50, blank=True)
  46. sex = models.IntegerField(choices=SEX_CHOICES, blank=True, null=True)
  47. activated = models.BooleanField(default=False)
  48. defaddr = models.ForeignKey('Address', blank=True, null=True, on_delete=models.SET_NULL)
  49. def __str__(self):
  50. return f'{self.user.username}'
  51. def short_bio(self):
  52. return truncatechars(self.bio, 50)
  53. class Address(models.Model):
  54. title = models.CharField(max_length=100)
  55. street1 = models.CharField(max_length=50)
  56. street2 = models.CharField(max_length=50, blank=True)
  57. postalcode = models.CharField(max_length=10)
  58. city = models.CharField(max_length=100)
  59. state = models.CharField(max_length=50)
  60. country = models.CharField(max_length=50)
  61. owner = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
  62. def __str__(self):
  63. return f'{self.title}'
  64. class Image(models.Model):
  65. photo = models.ImageField(default='avatar.png', upload_to='avatars/')
  66. owner = models.ForeignKey(User, on_delete=models.CASCADE)
  67. description = models.CharField(blank=True, max_length=100)
  68. def __str__(self):
  69. return str(self.description)
  70. #avatar = models.OneToOneField("Image", on_delete=models.CASCADE)

Powered by TurnKey Linux.