Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError u'parent' at mptt\forms.py in __init__, line 165 #140

Closed
tom200808 opened this issue Aug 13, 2013 · 12 comments
Closed

KeyError u'parent' at mptt\forms.py in __init__, line 165 #140

tom200808 opened this issue Aug 13, 2013 · 12 comments

Comments

@tom200808
Copy link

20130813111212
in the admin.py, it NOT work:

class CategoryAdmin(MPTTModelAdmin, SortableModelAdmin):
    sortable = 'order'
admin.site.register(Category, CategoryAdmin)

but work when remove MPTTModelAdmin or SortableModelAdmin, as follow:

class CategoryAdmin(MPTTModelAdmin):

or

class CategoryAdmin(SortableModelAdmin):

Error message :
KeyError at /admin/edition/category/
u'parent'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/edition/category/
Django Version: 1.5.1
Exception Type: KeyError
Exception Value:
u'parent'
Exception Location: E:\myenv\lib\site-packages\mptt\forms.py in init, line 165
Python Executable: E:\myenv\Scripts\python.exe
Python Version: 2.7.4
Python Path:
['E:\myenv\EDMIS3',
'E:\myenv\EDMIS3',
'C:\Windows\system32\python27.zip',
'E:\myenv\DLLs',
'E:\myenv\lib',
'E:\myenv\lib\plat-win',
'E:\myenv\lib\lib-tk',
'E:\myenv\Scripts',
'D:\dev\python\Lib',
'D:\dev\python\DLLs',
'D:\dev\python\Lib\lib-tk',
'E:\myenv',
'E:\myenv\lib\site-packages']
Server time: 星期二, 13 八月 2013 11:03:28 +0800

source code:

models.py

class Category(MPTTModel):
    name = models.CharField(max_length=50, unique=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
     # Sortable property
    order = models.PositiveIntegerField()

    class MPTTMeta:
        order_insertion_by = ['order']

    # It is required to rebuild tree after save, when using order for mptt-tree
    def save(self, *args, **kwargs):
        super(Category, self).save(*args, **kwargs)
        Category.objects.rebuild()

    def __unicode__(self):
        return self.name

admin.py

class CategoryAdmin(MPTTModelAdmin, SortableModelAdmin):
    sortable = 'order'

admin.site.register(Category, CategoryAdmin)
@darklow
Copy link
Owner

darklow commented Aug 13, 2013

Which version of MPTT are you using?

@tom200808
Copy link
Author

mptt version 0.6.0
suit version:0.2.3
django version:1.5.1

@darklow
Copy link
Owner

darklow commented Aug 15, 2013

Fix available in latest v0.2.4

darklow added a commit that referenced this issue Sep 23, 2013
when using sortable in combination with latest django-mptt.
Refactored that now form Meta widgets are applied in
get_change_list_form() method, which means any form will get
required Meta class widgets.
@shenzia
Copy link

shenzia commented Oct 3, 2013

Please, help me! I have issue as your - tom200808. How you fixed up its?

@darklow
Copy link
Owner

darklow commented Oct 3, 2013

@shenzia Have you updated to latest django-suit version v0.2.5 and latest django-mptt app?

@shenzia
Copy link

shenzia commented Oct 3, 2013

django-suit==0.2.4
django-mptt==0.6.0

@darklow
Copy link
Owner

darklow commented Oct 3, 2013

@shenzia latest is not v0.2.4 but v0.2.5

pip install django-suit -U

@shenzia
Copy link

shenzia commented Oct 3, 2013

I done --upgrade, but issue didn't disappeared..

@shenzia
Copy link

shenzia commented Oct 3, 2013

models.py

class Contacts(MPTTModel):
    name = models.CharField(u"Имя отправителя", max_length=64, blank=True, null=True)
    email = models.EmailField(u"Email", max_length=75, blank=True, null=True)
    adress = models.CharField(u"Адрес отправителя", max_length=150, blank=True, null=True)
    site = models.ForeignKey(Site, verbose_name='Сайты', blank = True, default=True)
    objects = models.Manager()
    on_site = CurrentSiteManager()
    username = models.ForeignKey(User, default = True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    def __unicode__(self):
        return u'%s' % str(self.name)

    class MPTTMeta:
        verbose_name = u"Контакт"
        verbose_name_plural = u"Контакты"
        order_insertion_by = ['name']
        permissions = (
            ('view_contacts', 'View contacts'),
        )

admins.py

class ContactsAdmin(MPTTModelAdmin, TranslationAdmin):
    list_display = ('name', 'email', 'adress',)
    list_display_links = ('name', 'email',)
    list_filter = (ContactsFilter,)
    ordering = ('name',)
    fieldsets = [
        ('Contacts', {'fields': ['name', 'email', 'adress']}),
        ('Email information', {'fields': ['site', 'username'], 'classes':['collapse']}),
    ]
    class Media:
        js = (
            '/static/modeltranslation/js/force_jquery.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js',
            '/static/modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('/static/modeltranslation/css/tabbed_translation_fields.css',),
        }


admin.site.register(Contacts, ContactsAdmin)

@darklow
Copy link
Owner

darklow commented Oct 4, 2013

@shenzia please post also full error stack (use dpaste.com link from Django error view)

@shenzia
Copy link

shenzia commented Oct 4, 2013

thanks for your help, but i remove MPTTModelAdmin. But have a new problem. Doesn't display tabs in admin. I used doc https://django-modeltranslation.readthedocs.org/en/0.6/admin.html#using-tabbed-translation-fields and https://github.com/jmagnusson/grappelli-modeltranslation.
Django==1.5.4
MySQL-python==1.2.4
PIL==1.1.7
Pillow==2.1.0
South==0.8.2
argparse==1.2.1
distribute==0.7.3
django-appconf==0.6
django-filebrowser==3.5.2
django-grappelli==2.4.6
django-guardian==1.1.1
django-modeltranslation==0.6.1
django-mptt==0.6.0
django-session-csrf==0.5
django-session-csrf-cookie==0.1
django-staticfiles==1.2.1
django-suit==0.2.5
grappelli-modeltranslation==0.1.1
psycopg2==2.5.1
six==1.4.1
wsgiref==0.1.2
But at the current moment i have http://rghost.ru/49137128.
Excuse me for my bad english..

admin.py
.....
class ContactsAdmin(TranslationAdmin):
list_filter = (ContactsFilter,)
class Media:
js = (
'/static/modeltranslation/js/force_jquery.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js',
'/static/modeltranslation/js/tabbed_translation_fields.js',
)
css = {
'screen': ('/static/modeltranslation/css/tabbed_translation_fields.css',),
}

fieldsets = [
    ('Contacts', {'fields': ['name', 'email', 'adress']}),
    ('Email information', {'fields': ['site', 'username'], 'classes':['collapse']}),
]

models.py
...
class Contacts(models.Model):
name = models.CharField(u"Имя отправителя", max_length=128, blank=True, null=True)
email = models.EmailField(u"Email", max_length=75, blank=True, null=True)
adress = models.CharField(u"Адрес отправителя", max_length=150, blank=True, null=True)
site = models.ForeignKey(Site, verbose_name='Сайты', blank = True, default=True)
objects = models.Manager()
on_site = CurrentSiteManager()
username = models.ForeignKey(User, default = True)

def __unicode__(self):
    return u'%s' % str(self.name_en)

class Meta:
    verbose_name = u"Контакт"
    verbose_name_plural = u"Контакты"
    permissions = (
        ('view_contacts', 'View contacts'),
    )

settings.py
USE_I18N = True
gettext_noop = lambda s: s

here is all the languages supported by the CMS

PAGE_LANGUAGES = (
('ru', 'Russian'),
('en', 'English'),
)

copy PAGE_LANGUAGES

languages = list(PAGE_LANGUAGES)

redefine the LANGUAGES setting in order to be sure to have the correct request.LANGUAGE_CODE

LANGUAGES = languages
MODELTRANSLATION_DEFAULT_LANGUAGE = 'ru'
MODELTRANSLATION_TRANSLATION_REGISTRY = 'filebrowser_crop.info.translation'

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.redirects',
'grappelli.dashboard',
'grappelli',
'grappelli_modeltranslation',
'modeltranslation',
'django.contrib.admin',
'django.contrib.admindocs',
...
)

Please help me again..

@darklow
Copy link
Owner

darklow commented Oct 4, 2013

@shenzia django-modeltranslation is not supported yet. For suppoerted apps see #3
PS. If issue is not related, you should better open new issue, rather than comment to another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants