0

I'm new to FanDjango, and trying to understand something. I've got everything set up and working beautifully, and I can pole request.facebook.user and get info.

But now, I want to develop an application that has more info than just Facebook gives me about each user. For example, I want to store up/down votes this user has mode on other objects (i.e. relations). I want to store user settings. Etc... The standard "Django Way" is to use a User Profile, but I don't know how to connect FanDjango's user to the user profile.

I'm unclear how to do this.

I looked into django-facebook before fandjango, and I couldn't get it to work which is why I moved to this. What they do is, they allow your user-profile to inherit from their user definition. Can the same kind of thing work here, or should I be doing something different?

Thanks

Edan Maor
  • 9,772
  • 17
  • 62
  • 92

1 Answers1

2

Well you can simply create a Profile model and give it a OneToOneField pointing to the Fandjango profile

class Profile(models.Model):
     facebook_user = models.OneToOneField("fandjango.User")
     votes = ...

which will allow you to get the Fandjango profile given the Profile and visa versa:

request.facebook.user.profile

and in reverse:

profile.facebook_user 

An issue with this is that because you aren't using django.contrib.auth at all, you don't get any of it's nice features such as being able to use {% if user.is_authenticated %} etc.

EDITED TO ADD:

Extra details provided here: https://github.com/jgorset/fandjango/issues/63#issuecomment-4988917

Then I just listen for the post_save signal of "Fandjango.models.User" and when the "created" parameter is set, I instantiate the Profile model.

@receiver(post_save, sender=User)
def profile_creation(sender, instance, created, **kwargs):
    if created:
        profile, created = Profile.objects.get_or_create(user=instance)
Edan Maor
  • 9,772
  • 17
  • 62
  • 92
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • Yes, that's probably the approach I will take. Is it really a problem losing the django.contrib.auth, if I'm a Facebook app and will only have Facebook users? – Edan Maor Apr 05 '12 at 14:04
  • 1
    This is what some user on the project's GitHub answered to the same question, and was confirmed by FanDjango's author as the right approach. See: https://github.com/jgorset/fandjango/issues/63#issuecomment-4988917 – Edan Maor Apr 07 '12 at 08:17