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 [email protected].
To post to this group, send email to [email protected].
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.

Reply via email to