I have a problem. It happens that when using "python manage.py createsuperuser " it only allows me to configure the user but neither the password nor the email appears, on the contrary, only errors appear.
I'm new to this, I don't know if I missed something. I add the code:
admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User, Post, Comment, PostView, Like
admin.site.register(Post)
admin.site.register(PostView)
admin.site.register(Comment)
admin.site.register(Like)
admin.site.register(User, UserAdmin)
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
def __str__(self):
return self.username
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'carros',
'bootstrap4',
'posts',
]
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
SITE_ID = 1
AUTH_USER_MODEL='posts.User'
LOGIN_URL = '/accounts/login'
LOGIN_REDIRECT_URL = '/home/'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
The errors that appear to me are the following
I add the models
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
def __str__(self):
return self.username
class Post(models.Model):
title=models.CharField(max_length=100)
content=models.TextField()
thumbnail=models.ImageField()
publish_date=models.DateTimeField(auto_now_add=True)
last_update=models.DateTimeField(auto_now=True)
author=models.ForeignKey(User, on_delete=models.CASCADE)
slug=models.SlugField()
def __str__(self):
return self.title
class Comment(models.Model):
user=models.ForeignKey(User, on_delete=models.CASCADE)
post=models.ForeignKey(Post,on_delete=models.CASCADE)
timestamp=models.DateTimeField(auto_now_add=True)
content=models.TextField()
def __str__(self):
return self.user.username
class PostView(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.user.username
class Like(models.Model):
user=models.ForeignKey(User, on_delete=models.CASCADE)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
def __str__(self):
return self.user.username
I tell you, the error you have until the last one:
It is indicating that in your Post model you must have a ForeignKey to a user, share this model to see how it is.
Analyzing a bit then I ask you, have you already generated all your migrations and applied them with makemigrations and migrate before? Since this is an option, you have not generated the migrations or you have not applied them and therefore there is no such relationship. Your migrations should be in app_name/migrations/0001_initial.py etc. You can check it this way:
And see if it generates any migration, if so then apply it with migrate.
Also, have you already verified that your application where you have the Post model is in the INSTALLED_APPS of your settings.py?
Updated You can try doing this, comment django.contrib.admin:
INSTALLED_APPS = [ # 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles ', 'django.contrib.sites',
]
And comment the url:
you execute
If the migrations are applied correctly then uncomment 'django.contrib.admin' from your installed_apps and url.