Answer the question
In order to leave comments, you need to log in
How to bind User model to posts?
class User(models.Model):
user_first_name = models.CharField(max_length=25)
user_lost_name = models.CharField(max_length=25)
user_old = models.IntegerField(default=0)
reg_date = models.DateTimeField('date registration')
def __str__(self):
return self.user_first_name
class Post(models.Model):
<b>Label = models.ForeignKey(User)</b>
Text = models.CharField(max_length=500)
Type = models.CharField(max_length=90)
Date = models.DateTimeField(auto_now_add=False)
Views = models.IntegerField(default=0)
Comments = models.IntegerField(default=0)
def __str__(self):
return self.Text
Answer the question
In order to leave comments, you need to log in
1. Your keyboard would be taken away for capital letters in variable names. Be sure to read pep8 !
2. Run the migration
python manage.py makemigrations
python manage.py migrate
“Write code as if it were accompanied by a violent psychopath who knows where you live.” © Steve McConnell
Here is an example of what you want to do as I understand it.
Pay attention to the line author = models.ForeignKey('auth.User')
It says that the post will be linked to one of the users registered on the site.
Then you can simply edit the auth.User model and expand it as you need
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question