I have created a custom user model which is working fine. The problem is when access the user from foreign key, it throws me :
DETAIL: Key (author_id)=(51) is not present in table "auth_user".
My custom user is userauth, clearly the model still looking for the original User model instead of the custom one.
Here is what I did:
#settings.py
AUTH_USER_MODEL = 'userauth.UserAuth'
#models.py
from django.conf import settings
User = settings.AUTH_USER_MODEL
class Post(models.Model):
title = models.CharField(max_length=255)
content = models.TextField()
author = models.ForeignKey(User, null=True,blank=True,default=None)
#admin.py
class AdminPost(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
if getattr(obj, 'author', None) is None:
obj.author = request.user
obj.save()