Menu

#519 user or profile didnt have attribute facebook_id

open
nobody
None
2016-03-02
2015-02-17
Anonymous
No

Originally created by: jblondeau2

Hello,

I'm using django 1.7 on python 3.4 an I'm having this F*** error showing just after every try to login or register on /facebook/example/

I've tried every settingsI found for similar problem on the entire Web but it still doesn't work... is this app still maintained?

There you will find an extract from my UserProfile model (of course I've already specified AUTH_USER_MODEL and AUTH_PROFILE_MODULE):

# UserProfile Custom Class
class UserProfile(FacebookProfileModel):
    #...
    user = models.OneToOneField(User, related_name='user_profile', blank=True, null=True)
    #...

    # Django_Facebook Post Receiver
    @receiver(post_save)
    def create_profile(sender, instance, created, **kwargs):
        """Create a matching profile whenever a user object is created."""
        profile_model = None

        if sender == get_user_model():
            user = instance
            profile_model = get_profile_model()
        if profile_model == get_profile_model() and created:
            profile, new = UserProfile.objects.get_or_create(user=instance)


    post_save.connect(create_profile, sender=User)

#Change auth model to unique email
User._meta.get_field('email')._unique = True

#Autogenerate profile
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

Thank you for the help.

Discussion

  • Anonymous

    Anonymous - 2015-02-25

    Originally posted by: timonweb

    It happens because Django 1.7 doesn't have get_profile() method on a user model and Django Facebook relies on it. What you may do is:

    1) Create custom user model as per Django 1.7 instructions and add get_profile() method there. That method should return profile object.

    2) Or go and monkeypatch current user model and add get_profile() method that returns profile object.

     
  • Anonymous

    Anonymous - 2016-03-02

    Originally posted by: jsvaughan

    As tim says, 1.7 drops the get_profile method from the User class. If like me you are still using separate user and userprofile classes and switched from .get_profile to just .profile to navigate by orm relation instead of merging the two then you'll get this problem.

    The quick fix is to patch the method back in:

    from django.contrib.auth.models import User
    
    def get_profile(self):
        return self.profile
    
    User.add_to_class("get_profile", get_profile)
    
     

Log in to post a comment.

MongoDB Logo MongoDB