当我从shell进行迁移/迁移/获取时-除了我的API查询集中:
models.py
class NewsManager(models.Manager):
def get_queryset(self):
locale = get_language()
return super().get_queryset().annotate(title=F('title_' + locale), body=F('body_' + locale),
short_description=F('short_description_' + locale),
seo_title=F('seo_title_' + locale))
class News (models.Model):
class Meta:
verbose_name = _('Новини')
ordering = ("-created_at",)
title_uk = models.CharField(max_length=255, blank=False)
title_en = models.CharField(max_length=255, blank=True)
seo_title_uk = models.CharField(max_length=255, blank=True)
seo_title_en = models.CharField(max_length=255, blank=True)
short_description_uk = RichTextField(blank=False)
short_description_en = RichTextField(blank=True)
body_uk = RichTextField(blank=False)
body_en = RichTextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
published = models.BooleanField(default=False)
objects = NewsManager()
api / views.py
class NewsAPIView(generics.ListAPIView):
"""
list:
Return a list of all news
"""
serializer_class = NewsPreviewSerializer
def get_queryset(self):
return News.objects.all().exclude(published=False)
class NewsDetailAPIView(generics.RetrieveAPIView):
"""
get:
Return one News obj by id
"""
serializer_class = NewsSerializer
queryset = News.objects.all()
lookup_field = 'id'
TypeError: must be str, not NoneType
return super().get_queryset().annotate(title=F('title_' + locale), body=F('body_' + locale),