diff --git a/docs/installation.rst b/docs/installation.rst index 826f96f1..c335f219 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -102,23 +102,27 @@ Be sure to run manage.py syncdb after setting this up. Otherwise Django Facebook provides an abstract model which you can inherit like this:: - from django_facebook.models import FacebookProfileModel - - - class MyCustomProfile(FacebookProfileModel): - user = models.OneToOneField('auth.User') - .... - - from django.contrib.auth.models import User - from django.db.models.signals import post_save - - #Make sure we create a MyCustomProfile when creating a User - def create_facebook_profile(sender, instance, created, **kwargs): - if created: - MyCustomProfile.objects.create(user=instance) - - post_save.connect(create_facebook_profile, sender=User) - +from django.db import models +from django.dispatch.dispatcher import receiver +from django_facebook.models import FacebookModel +from django.db.models.signals import post_save +from django_facebook.utils import get_user_model, get_profile_model +from your_project import settings + + +class MyCustomProfile(FacebookModel): + user = models.OneToOneField(settings.AUTH_USER_MODEL) + +@receiver(post_save) +def create_profile(sender, instance, created, **kwargs): + """Create a matching profile whenever a user object is created.""" + if sender == get_user_model(): + user = instance + profile_model = get_profile_model() + if profile_model == MyCustomProfile and created: + profile, new = MyCustomProfile.objects.get_or_create(user=instance) + +Remember to update AUTH_PROFILE_MODULE in settings to your new profile. Don't forget to update your database using syncdb or south after this step. Note: You need a profile model attached to every user model. For new accounts this will get created automatically, but you will need to migrate older accounts. @@ -130,4 +134,4 @@ Test if everything is working and ensure you didn't miss a step somewhere. If you encounter any difficulties please open an issue. Of course you now want to customize things like the login button, the page after registration etc. -This is explained in the integration section. \ No newline at end of file +This is explained in the integration section.