Skip to content

Inline UserProfile id not being passed correctly in Django Admin (Django 1.6, YawdAdmin 0.7.0) #38

@jared-l

Description

@jared-l

Hi there, firstly: great project!

I have a problem using (i.e. editing, updating) models with Yawd-Admin (0.7.0) on Python 2.7.8 when applying modal = True in my Inline Django Admin classes using the Django Proxy model for User Profiles.

Using the following as simplified case (settings.py excluded, as well as INSTALLED_APPS, and associated imports):

# app_name/admin.py
class UserProfileInline(admin.StackedInline):
    model = UserProfile
    max_num = 1
    can_delete = False
    modal = True # This causes the error

class UserProfileAdmin(UserAdmin):
    inlines = (UserProfileInline, )

admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)

admin.autodiscover()
admin_site._registry.update(admin.site._registry)


# app_name/models.py
class UserProfile(models.Model):
    user = models.OneToOneField(User)
    website = models.URLField(blank=True)

I obtain the following error creating / editing a user (e.g.):

MultiValueDictKeyError at /admin/auth/user/3/ "u'userprofile-0-id'"

Since this inline is now associated with User, the extraneous information (website in this example) shows up as a Profile heading in the same page when creating a user (which is expected behavior). If this information (i.e. website) is added, and then saved; on the next page (the edit page), and a save is attempted, you obtain that error. This also occurs when you attempt to edit such a post. The only time you have a successful user creation / edit occurs when you don't modify any info in the class where modal = True is present.

Also, because of the first save when creating a user, the user is added (in the default django auth tables), regardless of the success of entry of extra information via modal = True.

I've looked quite deeply in the Yawd-Admin source, and for the life of me I cannot find why this information isn't passed correctly.

Furthermore, having tried a number of combinations, it seems to be a Yawd-Admin problem with how modal = True loads and passes the information - as the default Django admin has no problem with this. And, when modal isn't present, everything works perfectly as in the default Django admin.

UPDATE: The problem occurs even without modal = True if one follows the sequence: add extra info, and then modify it. It seems to be Yawd-Admin related as django-admin-bootstrap3 has no issues with it - as does the default Django admin site.

I would appreciate any insight anyone can offer on this, please.

Many thanks!

Metadata

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