Error whikle making existing fields translatable - model already has a field
See original GitHub issueI am trying to translate already existing fields on a model class. I got stuck at the very first step, which is subclassing TranslatableModel
class in Category
class, and adding TranslatedFields
wrapper to translate selected model fields. I am following a book ‘Django by Example’ as well as the django-parler
instructions on how to do that, however when I run manage.py makemigrations myapp "add_translation_model"
I am getting the following error :
File ..../env/lib/python3.5/site-packages/parler/models.py", line 965, in contribute_translations
raise TypeError("The model '{0}' already has a field named '{1}'".format(shared_model.__name__, name))
TypeError: The model 'Category' already has a field named 'name'
before applying django-parler
:
# models.py
class Category(models.Model):
name = models.CharField(max_length=200,
db_index=True)
slug = models.SlugField(max_length=200,
unique=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('shop:product_list_by_category',
args=[self.slug])
after applying django-parler
:
# models.py
class Category(TranslatableModel):
name = models.CharField(max_length=200,
db_index=True)
slug = models.SlugField(max_length=200,
unique=True)
translations = TranslatedFields(
name = models.CharField(max_length=200,
db_index=True),
slug = models.SlugField(max_length=200,
unique=True),
)
class Meta:
# ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('shop:product_list_by_category',
args=[self.slug])
I am using Django 1.10.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Making existing fields translatable(Django) - Stack Overflow
The fix for me was to prefix all fields in the original Model with an ... class Category(TranslatableModel): translations = TranslatedFields( name =...
Read more >Making existing fields translatable - django-parler
The following guide explains how to make existing fields translatable, and migrate the data from the old fields to translated fields. django-parler stores ......
Read more >How to create custom model fields - Django documentation
Keep this in mind when creating your own custom fields. The Django Field subclass you write provides the machinery for converting between your...
Read more >Looker error catalog | Google Cloud
A field referenced by a suggest_dimension parameter does not exist, has been commented out, or is excluded in an Explore by a fields...
Read more >Enable Data Translation for Custom Fields - Salesforce Help
Allow translation of data stored in custom fields on the Record Alert, Product, and Product Category objects. You can enable data translation on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same problem, my workaround:
It looks like this check:
does not work with Django 3.1.
getattr(shared_model, name)
returns adjango.db.models.query_utils.DeferredAttribute
and thus fails the test for being a model field. The comment above it seems outdated.My work around was:
_
to create a rename migration