class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
def __str__(self):
return self.name
class Author(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
def __str__(self):
return self.name
class Entry(models.Model):
blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
headline = models.CharField(max_length=255)
body_text = models.TextField()
pub_date = models.DateField()
mod_date = models.DateField()
authors = models.ManyToManyField(Author)
number_of_comments = models.IntegerField()
number_of_pingbacks = models.IntegerField()
rating = models.IntegerField()
def __str__(self):
return self.headline
>>> from apps.dictionaries.models import Entry,Blog,Author
>>> Entry.objects.all().values()[0]
out:
{'id': 1, 'headline': 'Entry_headline1', 'pub_date': datetime.date(2020, 7, 9), 'number_of_comments': 1, 'mod_date': datetime.date(2020, 7, 12), 'rating': 1, 'body_text': 'Entry_body_text1', 'blog_id': 1, 'number_of_pingbacks': 1}
Т.е нет field ‘authors’
Далее, если я явно указываю field authors, тогда получаю следующее:
>>> Entry.objects.all().values('authors')[0]
out:
{'authors': 2}
Как мне выбрать в нормальном виде? Т.е
{'id': 1, 'headline': 'Entry_headline1', ..., 'authors': ['Author_name1'], ['Author_name2']