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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. Sample user/profile models for testing. These aren't enabled by default in the
  3. sandbox
  4. """
  5. from django.contrib.auth.models import (
  6. AbstractUser, BaseUserManager, AbstractBaseUser)
  7. from django.db import models
  8. from django.utils import timezone
  9. from django.utils.encoding import python_2_unicode_compatible
  10. from oscar.core import compat
  11. from oscar.apps.customer import abstract_models
  12. class Profile(models.Model):
  13. """
  14. Dummy profile model used for testing
  15. """
  16. user = models.OneToOneField(compat.AUTH_USER_MODEL, related_name="profile",
  17. on_delete=models.CASCADE)
  18. MALE, FEMALE = 'M', 'F'
  19. choices = (
  20. (MALE, 'Male'),
  21. (FEMALE, 'Female'))
  22. gender = models.CharField(max_length=1, choices=choices,
  23. verbose_name='Gender')
  24. age = models.PositiveIntegerField(verbose_name='Age')
  25. # A simple extension of the core User model for Django 1.5+
  26. class ExtendedUserModel(AbstractUser):
  27. twitter_username = models.CharField(max_length=255, unique=True)
  28. class CustomUserManager(BaseUserManager):
  29. def create_user(self, email, password=None):
  30. now = timezone.now()
  31. email = BaseUserManager.normalize_email(email)
  32. user = self.model(email=email, last_login=now)
  33. user.set_password(password)
  34. user.save(using=self._db)
  35. return user
  36. def create_superuser(self, email, password):
  37. return self.create_user(email, password)
  38. # A user model which doesn't extend AbstractUser
  39. @python_2_unicode_compatible
  40. class CustomUserModel(AbstractBaseUser):
  41. name = models.CharField(max_length=255, blank=True)
  42. email = models.EmailField(unique=True)
  43. twitter_username = models.CharField(max_length=255, unique=True)
  44. USERNAME_FIELD = 'email'
  45. objects = CustomUserManager()
  46. def __str__(self):
  47. return self.email
  48. def get_full_name(self):
  49. return self.name
  50. get_short_name = get_full_name
  51. # A simple extension of the core Oscar User model
  52. class ExtendedOscarUserModel(abstract_models.AbstractUser):
  53. twitter_username = models.CharField(max_length=255, unique=True)