I
I
iFortunes2018-05-15 16:38:42
Django
iFortunes, 2018-05-15 16:38:42

How to add tabs to django admin?

Here are 2 classes in the model:

class Cat(models.Model):
    name = models.CharField("Название категории", max_length=128)
    status = models.BooleanField('Статус')
    attribute = models.ForeignKey('Atr', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "Категории"
        verbose_name_plural = "Категория"

class Prod(models.Model):
    title = models.CharField(max_length=100)
    category = models.ForeignKey('Cat', on_delete=models.CASCADE)
    image = models.ImageField("Изображение", blank=True)
    status = models.BooleanField('Статус')
    slug = models.SlugField(('ЧПУ'), max_length=60)

    def __str__(self):
        return self.title
    class Meta:
        verbose_name = "Товар"
        verbose_name_plural = "Товары"

And here is admin.py
class CatAttributeInline(admin.TabularInline):
    model = Prod
    extra = 1
    verbose_name_plural = 'Prod'
    suit_classes = 'suit-tab suit-tab-params'

class CatAdmin(admin.ModelAdmin):

    inlines = [CatAttributeInline]
    serch_fields = ['id', 'name']
    fieldsets = [
        ('General', {
            'classes': ('suit-tab', 'suit-tab-general',),
            'fields': ['name','status', 'attribute']
        }),
    ]

    suit_form_tabs = (('general', 'General'),
                      ('params', 'Параметры'))

So adding a tab in the category with the product works, but I need exactly up to the turn, so that the product has a tab with categories and does not work.
django.core.management.base.SystemCheckError
: SystemCheckError: System check identified some issues:
ERRORS:
: (admin.E202) 'all.Atr' has no ForeignKey to 'all.Prod'.
And just like from one model class, for example, goods, break the class fields into tabs.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question