F
F
FAILER MC2021-06-08 21:13:01
Django
FAILER MC, 2021-06-08 21:13:01

Error related to parler. How to fix?

When I try to migrate I get this error:

Traceback (most recent call last):
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/parler/models.py", line 931, in contribute_translations
    base = shared_model._parler_meta
AttributeError: type object 'Product' has no attribute '_parler_meta'

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 164, in handle
    changes = autodetector.changes(
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/db/migrations/autodetector.py", line 43, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/db/migrations/autodetector.py", line 128, in _detect_changes
    self.old_apps = self.from_state.concrete_apps
  File "/home/boeing/nitshop/env/myshop/lib/python3.8/site-packages/django/db/migrations/state.py", line 213, in concrete_apps
    self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)


I have no idea how to fix this, because. everything was done according to the methodology. The methods of the English-speaking forum members do not help, because I do not quite understand what they are talking about.

Here is my model:

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


class Category(TranslatableModel):
    translations = TranslatedFields(
        name = models.CharField(max_length=200,
                                db_index=True),
        slug = models.SlugField(max_length=200,
                                db_index=True,
                                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])


class Product(TranslatableModel):
    translations = TranslatedFields(
        name = models.CharField(max_length=200, db_index=True),
        slug = models.SlugField(max_length=200, db_index=True),
        description = models.TextField(blank=True)
    )
    category = models.ForeignKey(Category,
                                 related_name='products',
                                 on_delete=models.CASCADE)
    image = models.ImageField(upload_to='products/%Y/%m/%d',
                              blank=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    available = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    # class Meta:
    #    ordering = ('name',)
    #    index_together = (('id', 'slug'),)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('shop:product_detail',
                       args=[self.id, self.slug])


And here is the admin file:

from django.contrib import admin
from parler.admin import TranslatableAdmin
from .models import Category, Product


@admin.register(Category)
class CategoryAdmin(TranslatableAdmin):
    list_display = ['name', 'slug']

    def get_prepopulated_fields(self, request, obj=None):
        return {'slug': ('name',)}


@admin.register(Product)
class ProductAdmin(TranslatableAdmin):
    list_display = ['name', 'slug', 'price',
                    'available', 'created', 'updated']
    list_filter = ['available', 'created', 'updated']
    list_editable = ['price', 'available']

    def get_prepopulated_fields(self, request, obj=None):
        return {'slug': ('name',)}


What could be the error and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mva2204, 2022-04-15
@mva2204

Was a solution found for this error?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question