Skip to content

Error with GenericTabularInline #153

Open
@ar7n

Description

Hello, I have this error trying to use django-admin-sortable2 with GenericTabularInline

AttributeError at /admin/news/news/1/change/
type object 'ImageFormFormSet' has no attribute 'fk'
Request Method:	GET
Request URL:	http://localhost:8000/admin/news/news/1/change/
Django Version:	1.11.1
Exception Type:	AttributeError
Exception Value:	
type object 'ImageFormFormSet' has no attribute 'fk'
Exception Location:	/Users/arseny/www/villagio-realty/env/lib/python3.6/site-packages/django/forms/models.py in get_default_prefix, line 919
Python Executable:	/Users/arseny/www/villagio-realty/env/bin/python
Python Version:	3.6.1
Python Path:	
['/Users/arseny/www/villagio-realty/villagiorealty',
 '/Users/arseny/www/villagio-realty/villagiorealty',
 '/Users/arseny/www/villagio-realty',
 '/Users/arseny/www/villagio-realty/env/lib/python36.zip',
 '/Users/arseny/www/villagio-realty/env/lib/python3.6',
 '/Users/arseny/www/villagio-realty/env/lib/python3.6/lib-dynload',
 '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
 '/Users/arseny/www/villagio-realty/env/lib/python3.6/site-packages']
Server time:	Пт, 19 Май 2017 16:13:37 +0300`

models.py

from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from adminsortable.models import SortableMixin


class Image(SortableMixin):
    file = models.ImageField('Файл')
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True)
    object_id = models.PositiveIntegerField(null=True)
    content_object = GenericForeignKey('content_type', 'object_id')
    position = models.IntegerField('Позиция', default=0)

    def __str__(self):
        return self.file.url

    class Meta:
        verbose_name = 'Изображение'
        verbose_name_plural = 'Изображения'
        ordering = ('position',)

admin.py

from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline
from adminsortable2.admin import SortableInlineAdminMixin
from .models import News
from ..image.models import Image


class ImageInline(SortableInlineAdminMixin, GenericTabularInline):
    model = Image


class NewsAdmin(admin.ModelAdmin):
    inlines = (
        ImageInline,
    )

admin.site.register(News, NewsAdmin)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions