Guest User

Untitled

a guest
May 23rd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 KB | None | 0 0
  1. when i run command python manage.py migrate,
  2. i got following error
  3. raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
  4. ValueError: Related model 'account.MyUser' cannot be resolved
  5. please help me to solv that error.
  6. This is my 'account.MyUser.
  7.  
  8.  
  9.  
  10.  
  11.  
  12. from django.db import models
  13. from django.db import models
  14. from django.contrib.auth.models import (
  15.    BaseUserManager, AbstractBaseUser
  16. )
  17.  
  18.  
  19. class MyUserManager(BaseUserManager):
  20.    def create_user(self, email, date_of_birth, password=None):
  21.        """
  22.        Creates and saves a User with the given email, date of
  23.        birth and password.
  24.        """
  25.        if not email:
  26.            raise ValueError('Users must have an email address')
  27.  
  28.        user = self.model(
  29.            email=self.normalize_email(email),
  30.            date_of_birth=date_of_birth,
  31.        )
  32.        user.set_password(password)
  33.        user.save(using=self._db)
  34.        return user
  35.  
  36.    def create_superuser(self, email, date_of_birth, password=None):
  37.        """
  38.        Creates and saves a superuser with the given email, date of
  39.        birth and password.
  40.        """
  41.        user = self.create_user(
  42.            email,
  43.            password=password,
  44.            date_of_birth=date_of_birth,
  45.        )
  46.        user.is_admin = True    
  47.        user.save(using=self._db)
  48.        return user
  49.  
  50.  
  51. class MyUser(AbstractBaseUser):
  52.    email = models.EmailField(
  53.        verbose_name='email address',
  54.        max_length=255,
  55.        unique=True,
  56.    )
  57.    date_of_birth = models.DateField()
  58.    is_active = models.BooleanField(default=True)
  59.    is_admin = models.BooleanField(default=False)
  60.  
  61.    objects = MyUserManager()
  62.  
  63.    USERNAME_FIELD = 'email'
  64.    REQUIRED_FIELDS = ['date_of_birth']
  65.  
  66.    def __str__(self):
  67.        return self.email
  68.  
  69.    def has_perm(self, perm, obj=None):
  70.        "Does the user have a specific permission?"
  71.        # Simplest possible answer: Yes, always
  72.        return True
  73.  
  74.    def has_module_perms(self, app_label):
  75.        "Does the user have permissions to view the app `app_label`?"
  76.        # Simplest possible answer: Yes, always
  77.        return True
  78.  
  79.    @property
  80.    def is_staff(self):
  81.        "Is the user a member of staff?"
  82.        # Simplest possible answer: All admins are staff
  83.        return self.is_admin
  84.  
  85.  
  86.  
  87. class Guest_email(models.Model):
  88.    email=models.EmailField(max_length=254)
  89.    active=models.BooleanField(default=True)
  90.    updated=models.DateTimeField(auto_now=True)
  91.    timestamp=models.DateTimeField(auto_now_add=True)
  92.  
  93.    def __str__(self):
  94.         return self.email
Add Comment
Please, Sign In to add comment