Saturday, November 26, 2016

Re: Two profile types with OneToOneField relationship with User

It seems to work. Thanks

On Saturday, November 26, 2016 at 3:36:42 PM UTC+1, ludovic coues wrote:
Have you tried `getattr(u, 'individualprofile', None)` ?

2016-11-26 15:17 GMT+01:00  <elto...@gmail.com>:
> Hi guys
>
> I'm on Django 1.10, and as described shortly here: https://dpaste.de/Bgao, I
> have created an abstract user profile which is tied to Django's User model
> with OneToOneField relationship. So I have AbstractProfile, and then there
> are IndividualProfile and BusinessProfile, each of which inherits from
> AbstractProfile.
>
> The problem I have, is that, whenever I have a user object instance (i.e. u
> = User.objects.get(pk=1234)), I'm not sure how to determine whether the
> profile is of type Individual or Business.
>
> So either u.individualprofile or u.businessprofile throws an error, and
> obviously I want to avoid having errors.
>
> Any help is appreciated. Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3dac6122-c209-415e-af62-387988c384d3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cf38ec6e-201b-4c29-b0e1-d61d43f2a975%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment