mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #34620 -- Fixed serialization crash on m2m fields without natural keys when base querysets use select_related().
Regression in 19e0587ee5.
Thanks Martin Svoboda for the report.
This commit is contained in:
@@ -53,12 +53,24 @@ class Author(models.Model):
|
||||
return self.name
|
||||
|
||||
|
||||
class TopicManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().select_related("category")
|
||||
|
||||
|
||||
class Topic(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
category = models.ForeignKey(Category, models.CASCADE, null=True)
|
||||
objects = TopicManager()
|
||||
|
||||
|
||||
class Article(models.Model):
|
||||
author = models.ForeignKey(Author, models.CASCADE)
|
||||
headline = models.CharField(max_length=50)
|
||||
pub_date = models.DateTimeField()
|
||||
categories = models.ManyToManyField(Category)
|
||||
meta_data = models.ManyToManyField(CategoryMetaData)
|
||||
topics = models.ManyToManyField(Topic)
|
||||
|
||||
class Meta:
|
||||
ordering = ("pub_date",)
|
||||
|
||||
Reference in New Issue
Block a user