Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango user profile creation happening twice
    text
    copied!<p>I am seeing an error with Django user profile creation that has been asked before a few times, but the solutions to the other questions and the <a href="https://docs.djangoproject.com/en/dev/topics/signals/#preventing-duplicate-signals" rel="nofollow">Django docs recommended</a> fix is not working.</p> <p>I have a UserProfile model that I am trying to create when creating a new user object from the Django admin pages.(forgive me on syntax here, it has been a while since I used stack overflow)</p> <pre><code>class UserProfile(models.Model): user = models.OneToOneField(User) organization = models.IntegerField(null=True) phone = models.CharField(max_length=20, null=True, blank=True) phone_ext = models.CharField(max_length=8, null=True, blank=True) team_no = models.CharField(max_length=30, null=True, blank=True) post_save.connect(create_user_profile, sender=User, dispatch_uid="a.unique.string.that.does.not.help.me") User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]) </code></pre> <p>I have added the user profile to the UserAdmin class and unregistered/registered the admin site entries.</p> <pre><code>class UserProfileInline(admin.StackedInline): model = UserProfile can_delete = False verbose_name_plural = 'profile' class UserAdmin(UserAdmin): inlines = (UserProfileInline, ) actions = [set_organization] exclude = ('is_staff',) try: admin.site.unregister(User) admin.site.unregister(RegistrationProfile) admin.site.unregister(Group) ## Re-register UserAdminadmin.site.unregister(User) finally: admin.site.register(User, UserAdmin) admin.site.register(RegistrationProfile, RegistrationAdmin) admin.site.register(Group, GroupAdmin) </code></pre> <p>So each time that I try to go create a new user I always get a duplicate key error for the user_profile_user_id field. Looking at the logs there is two insert statements being ran on the user save. The first is missing all data input into the user profile fields in the admin interface. The second has all the data but fails since there was already the initial insert with just he user_id.</p> <p>I have searched the project over a few times looking for a duplicate import of my models.py for the UserProfile class and have found nothing.</p> <p>Does anyone have any ideas here?</p> <p>Thank you.</p> <p>--update --</p> <p>Django version is 1.3</p> <pre><code>imports in the profile/models.py from django.contrib.auth.models import User from django.db.models.signals import post_save, pre_save import logging </code></pre> <p>imports from the admin.py from django.contrib import admin from django.contrib.auth.models import Group from test.django.registration.models import RegistrationProfile from test.django.registration.admin import RegistrationAdmin from django.contrib.auth.admin import UserAdmin, GroupAdmin from django.contrib.auth.models import User from test.django.extranet.profile.models import UserProfile from test.django.common.models.ajrsonline.ajrsonline_users import AjrsonlineUsers from test.django.common.middleware.ajrs_ldap import AJRSOnlineLdapBackend</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload