简体   繁体   中英

Django Admin Classes that Override formfield_for_dbfield - Error

I have a bunch of FlatPages on my django website and would like to translate their content in different languages from the Admin using the django-modeltranslations pacakge. Here is my code:

class TinyMCEFlatPageAdmin(FlatPageAdmin):    
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name.startswith('content'):
            return db_field.formfield(widget=TinyMCE(attrs={'cols': 80, 'rows': 30},))
        return super().formfield_for_dbfield(db_field, **kwargs)

Basically, I created a TinyMCEFlatPageAdmin class from the default one FlatPageAdmin to display the Flatpage content in HTML on the admin site. As far as the translation is concerned, i added the following code:

class MyTranslatedFlatPageAdmin(TinyMCEFlatPageAdmin, TabbedTranslationAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        field = super().formfield_for_dbfield(db_field, **kwargs)
        self.patch_translation_field(db_field, field, **kwargs)
        return field

I have then registered the new MyTranslatedFlatPageAdmin class:

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, MyTranslatedFlatPageAdmin)

When i log in to the flatpage content page i receive the following error:

formfield_for_dbfield() takes 2 positional arguments but 3 were given

I am struggling to find out why as everything seems to be correct to me. Thanks in advance for your help

I fixed it by downgrading to version 0.13.1. It seems a bug with the version 0.15.0 of the package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM