1

I am using django-parler for language translation in an abstract class model but I get this error: raise TypeError("Can't create TranslatedFieldsModel for abstract class {0}".format(shared_model.__name__)) TypeError: Can't create TranslatedFieldsModel for abstract class MyClass

I want to know why I can't create an instance of this TranslatedFieldsModel in an abstract class. Are there some instance or some type of classes/objects that cannot be instantiated in an abstract class? I really don't know much about abstract classes, please explain to me why this TranslatedFieldsModel cannot be created and how to go about it

Here is a code example:

from django.db import models
from parler.models import TranslatableModel, TranslatedFields

class MyClass(TranslatableModel):
    translations = TranslatedFields(
        title = models.CharField(max_length=500)
    )
    class Meta:
        abstract = True

when I run my app I get the error above: My question now is why is this so that I cannot create this instance in my abstract class? How can I make this work?

  • [from the doc](https://docs.djangoproject.com/en/3.1/topics/db/models/#abstract-base-classes), Abstract base classes are useful when you want to put some common information into a number of other models. You write your base class and put abstract=True in the Meta class. ***This model will then not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to those of the child class.*** – JPG Sep 16 '20 at 08:44
  • Please post the relevant code. – ewokx Sep 16 '20 at 08:44
  • @ArakkalAbu I understand these things you have mentioned about an abstract class but am asking why in my case creating an instance of TranslatedFields inside an abstract class `MyClass` isn't working. And how I can make this work – omokehinde igbekoyi Sep 16 '20 at 10:17
  • @ewong I have edited the question to contain the relevant code. – omokehinde igbekoyi Sep 16 '20 at 10:19
  • Where is the ***object creation code snippets*** ? @omokehindeigbekoyi – JPG Sep 16 '20 at 10:27
  • @ArakkalAbu `translations = TranslatedFields( title = models.CharField(max_length=500) )` and when I run my app I get this error ` raise TypeError("Can't create TranslatedFieldsModel for abstract class {0}".format(shared_model.__name__)) TypeError: Can't create TranslatedFieldsModel for abstract class ProductFeature` – omokehinde igbekoyi Sep 16 '20 at 10:32
  • First I want to understand why this is so and then how to resolve it. – omokehinde igbekoyi Sep 16 '20 at 10:33
  • 2
    seems like [there is an open issue](https://github.com/django-parler/django-parler/issues/87) – JPG Sep 16 '20 at 10:46
  • @ArakkalAbu here is the object creation snippet `translations = TranslatedFields( title = models.CharField(max_length=500) )` – omokehinde igbekoyi Sep 16 '20 at 11:55

0 Answers0