models.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from django.contrib.auth.models import User
  2. from django.utils.translation import ugettext as _
  3. from django.db import models
  4. from . import constants
  5. class StoreProfile(models.Model):
  6. user = models.OneToOneField(
  7. User, unique=True, verbose_name=_("user"), related_name="my_profile"
  8. )
  9. company = models.CharField(max_length=30, blank=True, null=True)
  10. address1 = models.CharField(max_length=30)
  11. address2 = models.CharField(max_length=30)
  12. city = models.CharField(max_length=30)
  13. region = models.CharField(max_length=30, choices=constants.STATE_CHOICES)
  14. phone = models.CharField(max_length=30)
  15. country = models.CharField(max_length=30, choices=constants.COUNTRIES)
  16. country_other = models.CharField(max_length=30)
  17. postal_code = models.CharField(max_length=30)
  18. plus_four = models.CharField(max_length=4)
  19. @property
  20. def secondary_address(self):
  21. from accounts.profile import get_profile_secondary_address
  22. return get_profile_secondary_address(self.user)
  23. class SecondaryProfileAddress(models.Model):
  24. """ Users can have multiple addresses """
  25. profile = models.ForeignKey(StoreProfile)
  26. address_from = models.DateField(blank=True, null=True)
  27. address_to = models.DateField(blank=True, null=True)
  28. company = models.CharField(max_length=30, blank=True, null=True)
  29. first_name = models.CharField(max_length=30, blank=True, null=True)
  30. last_name = models.CharField(max_length=30, blank=True, null=True)
  31. address1 = models.CharField(max_length=30, blank=True, null=True)
  32. address2 = models.CharField(max_length=30, blank=True, null=True)
  33. city = models.CharField(max_length=30, blank=True, null=True)
  34. region = models.CharField(
  35. max_length=30, choices=constants.STATE_CHOICES, blank=True, null=True
  36. )
  37. phone = models.CharField(max_length=30, blank=True, null=True)
  38. country = models.CharField(
  39. max_length=30, choices=constants.COUNTRIES, blank=True, null=True
  40. )
  41. country_other = models.CharField(max_length=30, blank=True, null=True)
  42. postal_code = models.CharField(max_length=30, blank=True, null=True)
  43. plus_four = models.CharField(max_length=4, blank=True, null=True)
  44. email = models.CharField(max_length=30, blank=True, null=True)