Such a problem: there is an application for viewing and creating news entries. There is a need to save in the database the username of the author (ie, authorized user). Using this material I connected the User model to my news model.
The problem is that django does not automatically enter the name of an authorized user, but offers the author a choice of any name that exists in User:
models.py:
from django.db import models from django.utils import timezone from django.contrib.auth.models import User class NewsContent(models.Model): title = models.CharField(max_length = 130) post = models.TextField() date = models.DateTimeField(default=timezone.now) autor = models.ForeignKey( 'auth.User',on_delete=models.CASCADE, null=True) def __str__(self): return self.title
I understand why this does not work correctly, but I do not have enough knowledge and experience to solve the problem. Thank you in advance.