django-hvad 翻译 django-rest-framework 的模型
Django-hvad translate model of django-rest-framework
我正在尝试在 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'
我在翻译我的模型时犯了什么错误吗?感谢您的帮助!
models.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.
serializers.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
我正在尝试在 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'
我在翻译我的模型时犯了什么错误吗?感谢您的帮助!
models.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.
serializers.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