Re: User has no dcf_profile : RelatedObjectDoesNotExist

2017-06-16 Thread Melvyn Sopacua
On Friday 16 June 2017 03:17:00 Nabil BOUDERBALA wrote:
> After extending an existing user model, I get
> RelatedObjectDoesNotExist exception with a value User has no
> dcf_profile. I seems that dcf_profile isn't created automatically for
> each user.

That's correct. That's your job and the documentation gives you a hint on how 
to do it:

These profile models are not special in any way - they are just Django models 
that happen 
to have a one-to-one link with a user model. As such, they aren’t auto created 
when a user 
is created, but a django.db.models.signals.post_save[1] could be used to create 
or update 
related models as appropriate.

-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/1.11/ref/signals/#django.db.models.signals.post_save

-- 
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+unsubscr...@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/2503988.A6k4gYsYkB%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: User has no dcf_profile : RelatedObjectDoesNotExist

2017-06-16 Thread 'Abraham Varricatt' via Django users

On Friday, June 16, 2017 at 7:06:33 AM UTC-4, Nabil BOUDERBALA wrote:
>
> After extending an existing user model, I get RelatedObjectDoesNotExist 
> exception with a value User has no dcf_profile. I seems that dcf_profile 
> isn't created automatically for each user.
>

It took me awhile to figure out that dcf_profile is the text you use as 
related_name for the User model. 


 

> Please take a look at my model, view and form below and tell me how can I 
> correct my views file?
>
My views.py :
>
> @method_decorator(login_required)def dispatch(self, *args, **kwargs):
> if not self.request.user.dcf_profile.allow_add_item():
>
>
It looks like this is where you are having trouble. The code is trying to 
call the dcf_profile attribute/method from the user object - which doesn't 
exist. 

Your end goal appears to be to call the all_add_item() function. Why not 
grab an instance of your CustomUser first and invoke it on that? Something 
like,

def dispatch(self, *args, **kwargs):
user = self.request.user
my_user = CustomUser.objects.get(auth_user_ptr=user)  # Assuming you 
have entry in your database
if not my_user.allow_add_item():


Yours,
Abraham V.

-- 
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+unsubscr...@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/022133ae-25f4-4bc4-82ce-aee7726932b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.