python manage.py inspectdb > users/models.py
이후
python manage.py migrate appname --fake-initial
models의 managed = True로 변경
이렇게 하면 이후 makemigrations와 migrate을 진행하여 기존 DB에도 변경을 줄 수 있다.
from django.db import models from django.contrib.auth.hashers import ( check_password, make_password, ) from django.contrib.auth.models import BaseUserManager, AbstractBaseUser ... ... class User(models.Model): ... ... USERNAME_FIELD = "username" REQUIRED_FIELDS = ["email"] def set_password(self, raw_password): self.password = make_password(raw_password) self._password = raw_password def check_password(self, raw_password): def setter(raw_password): self.set_password(raw_password) # Password hash upgrades shouldn't be considered password changes. self._password = None self.save(update_fields=["password"]) return check_password(raw_password, self.password, setter) def has_permission(self, request, view): return bool(request.user and request.user.is_authenticated) def set_unusable_password(self): # Set a value that will never be a valid hash self.password = make_password(None) @property def is_anonymous(self): """ Always return False. This is a way of comparing User objects to anonymous users. """ return False @property def is_authenticated(self): """ Always return True. This is a way to tell if the user has been authenticated in templates. """ return True