Search code examples
djangoadmin

Changes in admin utils module in Django


Recently I upgraded Django in my project from version 1.6.11 to version 1.8.7. Now I get an error in my accounts module. Piece of code and error:

from django.contrib.admin import util


self.add_fieldsets = (
    ( some_data ),
    ( some_data ),
)

...
obj.update({
    'fields': admin.util.flatten_fieldsets(self.add_fieldsets),
})

I get an error:

Exception Type:     AttributeError
Exception Value:    'module' object has no attribute 'util'

It's about this method admin.util.flatten_fieldsets(self.add_fieldsets) Was there any changes in this method in Django 1.8.x?


Solution

  • util modules were renamed to utils in Django 1.7 (release notes).

    To update your code for Django 1.7+, replace the import

    from django.contrib.admin import util
    

    with

    from django.contrib.admin import utils
    

    Then change the code to

    obj.update({
        'fields': utils.flatten_fieldsets(self.add_fieldsets),
    })