gpt4 book ai didi

python - django-hvad 翻译 django-rest-framework 的模型

转载 作者:行者123 更新时间:2023-11-28 18:15:39 24 4
gpt4 key购买 nike

我正在尝试在 Django 应用程序上实现 django-hvad,但是当我尝试启动 python manage.py runserver 时出现错误:

File "/Users/Philippe/Documents/DjangoApp/env/lib/python3.6/site-packages/hvad/manager.py", line 265, in _clone
return super(TranslationQueryset, self)._clone(**kwargs)
TypeError: _clone() got an unexpected keyword argument 'shared_model'

我在翻译我的模型时是否犯了任何错误?感谢您的帮助!

模型.py

class Opponent(TranslatableModel):
name = models.CharField(max_length=255, unique=True, null=True)
companyType = models.ForeignKey(CompanyType, on_delete=models.SET_NULL, blank=True, null=True, related_name='opponents')
pricing = models.ManyToManyField(Pricing, blank=True)
translations = TranslatedFields(
description = models.TextField(null=True, blank=True)
)

def __str__(self):
return "{}" .format(self.name)

def save(self, *args, **kwargs):
super(Opponent, self).save(*args, **kwargs) # Call the "real" save() method.

序列化器.py

class OpponentSerializer(TranslatableModelSerializer):
class Meta:
model = Opponent
fields = '__all__'

views.py

class OpponentViewSet(viewsets.ModelViewSet):
queryset = Opponent.objects.language().all()
serializer_class = OpponentSerializer

def get_queryset(self):
user_language = self.request.GET.get('language')
return Opponent.objects.language(user_language).all()

最佳答案

Django-hvad 与 Django 2 不兼容。这里是 the issue

关于python - django-hvad 翻译 django-rest-framework 的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48541819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com