Answer the question
In order to leave comments, you need to log in
How to attach a tag to a post in django?
I didn't really understand how to add a tag to a post...
MODELS.PY
class Post(models.Model):
date = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=32)
image = models.URLField()
content = models.TextField()
tag = models.ManyToManyField('Tag', blank=True, related_name='posts')
def __str__(self):
return self.title
class Tag(models.Model):
title = models.CharField(max_length=32)
def __str__(self):
return self.title
Answer the question
In order to leave comments, you need to log in
In the admin panel, if you select the created tag through the shell, then in the template it is displayed as main.Tag.None. (main - application name) How to fix this?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question