1
0
mirror of https://github.com/django/django.git synced 2024-11-18 07:26:04 +00:00
django/tests/auth_tests/models/with_foreign_key.py
Tim Graham 590b8c1c57 Removed unnecessary app_label='auth' on auth_tests models.
This is a relic of when the tests were stored in contrib.auth.tests.
2015-10-27 08:19:45 -04:00

26 lines
909 B
Python

from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, Group
from django.db import models
class Email(models.Model):
email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
class CustomUserWithFKManager(BaseUserManager):
def create_superuser(self, username, email, group, password):
user = self.model(username_id=username, email_id=email, group_id=group)
user.set_password(password)
user.save(using=self._db)
return user
class CustomUserWithFK(AbstractBaseUser):
username = models.ForeignKey(Email, models.CASCADE, related_name='primary')
email = models.ForeignKey(Email, models.CASCADE, to_field='email', related_name='secondary')
group = models.ForeignKey(Group, models.CASCADE)
custom_objects = CustomUserWithFKManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email', 'group']