On Sat, Apr 11, 2015 at 9:27 AM, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
> On 10/04/2015 11:06 PM, Larry Martell wrote:
>>
>> Reading this:
>> https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#extending-the-existing-user-model
>>
>> I see this:
>>
>> These profile models are not special in any way - they are just Django
>> models that happen to have a one-to-one link with a User model. As
>> such, they do not get auto created when a user is created, but a
>> django.db.models.signals.post_save could be used to create or update
>> related models as appropriate.
>>
>> I have a related model set up just like this, and when I new user is
>> created a row in the related table is created. So what does this
>> comment in the docs mean when it says "they do not get auto created
>> when a user is created"?
>
>
> I suspect you have established the profile model in the Admin where it
> appears in-line with the user model. It is the Admin adding the 1:1 foreign
> key to the profile which creates the record on saving.
>
> Remember, the Admin is an app and not part of core Django. The docs you
> quote are about core Django.
>
> If you are not using the Admin you might need to use the post_save signal
> for the user model to create the profile model.

That makes sense, but just above the text I quoted from the docs, the
code example shown uses the Admin, so it's confusing, at least to me.

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from my_user_profile_app.models import Employee

# Define an inline admin descriptor for Employee model
# which acts a bit like a singleton
class EmployeeInline(admin.StackedInline):
    model = Employee
    can_delete = False
    verbose_name_plural = 'employee'

# Define a new User admin
class UserAdmin(UserAdmin):
    inlines = (EmployeeInline, )

# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)from

django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from my_user_profile_app.models import Employee

# Define an inline admin descriptor for Employee model
# which acts a bit like a singleton
class EmployeeInline(admin.StackedInline):
    model = Employee
    can_delete = False
    verbose_name_plural = 'employee'

# Define a new User admin
class UserAdmin(UserAdmin):
    inlines = (EmployeeInline, )

# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY4Dr0zCngu292yXmq4dbJoYLFUM2o2epFoZ11UqQ8rQFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to