Navigation Menu

Skip to content

Commit

Permalink
Changing documentation piece about creating a custom user profile to …
Browse files Browse the repository at this point in the history
…reflect code in member/models.py
  • Loading branch information
kozikow committed Jan 6, 2014
1 parent cd609ce commit 8378581
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions docs/installation.rst
Expand Up @@ -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.
Expand All @@ -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.
This is explained in the integration section.

0 comments on commit 8378581

Please sign in to comment.