Answer the question
In order to leave comments, you need to log in
Django Python how to set ForeignKey with User model?
Can't add news. How to set correct ForeignKey with User model?
Answer the question
In order to leave comments, you need to log in
I suppose that somehow your models.py file looks like this and the news model is described in it approximately like this.
The user field is responsible for the user:
# models.py
from django.db import models
from django.contrib.auth.models import User
# Модель новости
class News(models.Model)
title = models.CharField(max_length=250, verbose_name='Заголовок')
text = models.TextField(verbose_name='Текст новости')
user = models.ForeignKey(User, verbose_name='Автор')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question