Re: Have get_profile() delegate to one of several profile models depending on type of user

2008-02-01 Thread Chris Pratt

Thanks for the responses everyone. My final approach to this issue has
gone more along the lines of Ivan's response, though with a twist. I
now have a generic UserProfile model which is returned by the
get_profile() method. All this model stores is the foreign key to the
user and a 'user_type'. I have a method on this model that uses a
modified form of Auth's own get_profile() method to retrieve the
appropriate model based on the user type. Essentially UserProfile acts
as a middleman between the User model and the appropriate Profile
model for the situation.

I agree with Ivan. I'm not fond of this approach either, but short of
something like single table inheritance (which Django doesn't
support), there's really no other (good) way to approach the problem.
I guess the best approach would be to actually write my own
authentication system customized to my app. I could get rid of the
hackiness of my solution here, but that approach seems to have
problems of its own.

Chris Pratt

On Jan 29, 4:00 pm, forgems <[EMAIL PROTECTED]> wrote:
> What is the criteria in the User model that gives you users profile
> model ? If you don't have such a criteria in User's model then you
> have answered your question,
>
> On Jan 28, 9:11 pm, Chris Pratt <[EMAIL PROTECTED]> wrote:
>
> > This question has been asked a few times before, but doesn't seem to
> > be getting any responses.
>
> > I'm working on a project where we have three types of users, each
> > requiring vastly different profile models. The AUTH_PROFILE_MODULE
> > setting, obviously, allows only one profile to be specified.
>
> > One response to this question suggested branching from an intermediate
> > profile model. Thereby, you could call something like:
>
> > request.user.get_profile().get_for_user()
>
> > and it would return the appropriate profile. This seems like a fair
> > enough approach, but it's a bit kludgy, and certainly doesn't lend
> > itself towards DRY code that anyone can manipulate. What happens if
> > someone comes along later and doesn't know they're supposed to tack on
> > the extra method call?
>
> > It would be easy enough to rewrite the get_profile() method to pull
> > the right profile and then monkey patch the User model, but this feels
> > wrong.
>
> > What would be considered best practice here?
>
> > Thanks,
> > Chris Pratt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Have get_profile() delegate to one of several profile models depending on type of user

2008-01-29 Thread forgems

What is the criteria in the User model that gives you users profile
model ? If you don't have such a criteria in User's model then you
have answered your question,

On Jan 28, 9:11 pm, Chris Pratt <[EMAIL PROTECTED]> wrote:
> This question has been asked a few times before, but doesn't seem to
> be getting any responses.
>
> I'm working on a project where we have three types of users, each
> requiring vastly different profile models. The AUTH_PROFILE_MODULE
> setting, obviously, allows only one profile to be specified.
>
> One response to this question suggested branching from an intermediate
> profile model. Thereby, you could call something like:
>
> request.user.get_profile().get_for_user()
>
> and it would return the appropriate profile. This seems like a fair
> enough approach, but it's a bit kludgy, and certainly doesn't lend
> itself towards DRY code that anyone can manipulate. What happens if
> someone comes along later and doesn't know they're supposed to tack on
> the extra method call?
>
> It would be easy enough to rewrite the get_profile() method to pull
> the right profile and then monkey patch the User model, but this feels
> wrong.
>
> What would be considered best practice here?
>
> Thanks,
> Chris Pratt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Have get_profile() delegate to one of several profile models depending on type of user

2008-01-29 Thread [EMAIL PROTECTED]

You could create a UserProfile that is essentially just a single
member with a selectable type.

Depending on the response, go grab that other profile for the user.

Wrap this in a function:

def getRealProfile(user):
  p = user.get_profile()
  if p.Type == 'a':
return AProfile.objects.filter(user=user)[0]
  elif. ...

I don't really like this option too much though.


Ivan

On Jan 28, 12:11 pm, Chris Pratt <[EMAIL PROTECTED]> wrote:
> This question has been asked a few times before, but doesn't seem to
> be getting any responses.
>
> I'm working on a project where we have three types of users, each
> requiring vastly different profile models. The AUTH_PROFILE_MODULE
> setting, obviously, allows only one profile to be specified.
>
> One response to this question suggested branching from an intermediate
> profile model. Thereby, you could call something like:
>
> request.user.get_profile().get_for_user()
>
> and it would return the appropriate profile. This seems like a fair
> enough approach, but it's a bit kludgy, and certainly doesn't lend
> itself towards DRY code that anyone can manipulate. What happens if
> someone comes along later and doesn't know they're supposed to tack on
> the extra method call?
>
> It would be easy enough to rewrite the get_profile() method to pull
> the right profile and then monkey patch the User model, but this feels
> wrong.
>
> What would be considered best practice here?
>
> Thanks,
> Chris Pratt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Have get_profile() delegate to one of several profile models depending on type of user

2008-01-29 Thread Thomas Guettler

Hi,

A profile is like a one to one relation. Since the future of
OneToOneField is unknown I heard you should use ForeignKey() with
unique=True.

You can modify djangos User model (e.g. in your model file), and
give it a property to make the access easier. In this
get_myprofile() method, you can create myprofile, if it does not
exist up to now.

Since you want three different profiles, I would create three
properties. I think this is better than one property which
returns different model instances.

 Thomas


Am Montag, 28. Januar 2008 21:11 schrieb Chris Pratt:
> This question has been asked a few times before, but doesn't seem to
> be getting any responses.
>
> I'm working on a project where we have three types of users, each
> requiring vastly different profile models. The AUTH_PROFILE_MODULE
> setting, obviously, allows only one profile to be specified.
>
> One response to this question suggested branching from an intermediate
> profile model. Thereby, you could call something like:
>
> request.user.get_profile().get_for_user()
>
> and it would return the appropriate profile. This seems like a fair
> enough approach, but it's a bit kludgy, and certainly doesn't lend
> itself towards DRY code that anyone can manipulate. What happens if
> someone comes along later and doesn't know they're supposed to tack on
> the extra method call?
>
> It would be easy enough to rewrite the get_profile() method to pull
> the right profile and then monkey patch the User model, but this feels
> wrong.
>
> What would be considered best practice here?
>
> Thanks,
> Chris Pratt

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Have get_profile() delegate to one of several profile models depending on type of user

2008-01-28 Thread Chris Pratt

This question has been asked a few times before, but doesn't seem to
be getting any responses.

I'm working on a project where we have three types of users, each
requiring vastly different profile models. The AUTH_PROFILE_MODULE
setting, obviously, allows only one profile to be specified.

One response to this question suggested branching from an intermediate
profile model. Thereby, you could call something like:

request.user.get_profile().get_for_user()

and it would return the appropriate profile. This seems like a fair
enough approach, but it's a bit kludgy, and certainly doesn't lend
itself towards DRY code that anyone can manipulate. What happens if
someone comes along later and doesn't know they're supposed to tack on
the extra method call?

It would be easy enough to rewrite the get_profile() method to pull
the right profile and then monkey patch the User model, but this feels
wrong.

What would be considered best practice here?

Thanks,
Chris Pratt




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---