0

I'm creating an application in django that will eventually allow users to post pictures. The Pictures contain a ForeignKey to the User.

I want to be able to manipulate the User class as a model class as above, but I also want it to serve the functions of authorization etc., which django-registration/auth is handling right now.

So basically I have two classes; my own User class, and the auth_user class, each with their own tables in sqlite.

How should I go about associating the two? Should I use a OneToOne field or should I just extend the auth_user class to include all the functionality of the model User class?

River Tam
  • 3,096
  • 4
  • 31
  • 51

1 Answers1

2

I believe this is what you're looking for:

https://docs.djangoproject.com/en/1.4/topics/auth/#auth-profiles

You'll need to specify your custom class within your settings.py file using something like:

AUTH_PROFILE_MODULE = 'accounts.UserProfile'

Hope that helps.

themanatuf
  • 2,880
  • 2
  • 25
  • 39
  • That's great. Question, though. If I follow the "create_user_profile" bit from that link, will it automatically create a UserProfile when django-registration creates a User? If not, how can I do this? I'm really new to django. – River Tam Dec 04 '12 at 17:21
  • Also, what's the "post_save.connect" part? I don't really understand that in context. – River Tam Dec 04 '12 at 17:23
  • You'll only need that `create_user_profile` if you want to create a profile if one does not exist. Personally, I do not implement this. As for the `post_save.connect` it's just a callback that gets called after the user account is saved. Again, it's not necessary in every application, but if you wanted to send an email after an account was saved, you'd put it there. – themanatuf Dec 04 '12 at 17:29
  • So does that mean that, without the create_user_profile (or with it, either way), a new UserProfile will be created automatically with the default settings when a User is created? – River Tam Dec 04 '12 at 17:31
  • Not quite. If you do not have a `create_user_profile` defined, then if you try to get the profile for user `XYZ` you'll get a None object. If you do define that function, then it will create a default profile for user `XYZ` for you. – themanatuf Dec 04 '12 at 17:46