Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:29:38+00:00 2026-05-15T16:29:38+00:00

In my application I have an extended User model called UserProfile. This user can

  • 0

In my application I have an extended User model called UserProfile. This user can add up to 4 Friend models. Each added Friend is related 1 to 1 with UserProfile. In my AddFriend form I have a custom cleaning method, for pid field (personal id). This clean_pid should check if the user with given pid is already registered/added as friend and return proper ValidationError. After submitting the form (with no instances in Friend table) I’m getting :

DoesNotExist at /user/add_friend/
UserProfile matching query does not exist.

If there are no users matching sent ‘pid’, it’s value should be returned. Why it’s not working ?

Traceback :

File "/home/rails/fandrive/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/rails/fandrive/site-packages/django/contrib/auth/decorators.py" in __call__
  78.             return self.view_func(request, *args, **kwargs)
File "/home/rails/fandrive/accounts/views.py" in add_friend
  22.         if form.is_valid():
File "/home/rails/fandrive/site-packages/django/forms/forms.py" in is_valid
  120.         return self.is_bound and not bool(self.errors)
File "/home/rails/fandrive/site-packages/django/forms/forms.py" in _get_errors
  111.             self.full_clean()
File "/home/rails/fandrive/site-packages/django/forms/forms.py" in full_clean
  243.                     value = getattr(self, 'clean_%s' % name)()
File "/home/rails/fandrive/accounts/forms.py" in clean_pid
  48.             user = UserProfile.objects.get(pid=self.cleaned_data['pid'])
File "/home/rails/fandrive/site-packages/django/db/models/manager.py" in get
  120.         return self.get_query_set().get(*args, **kwargs)
File "/home/rails/fandrive/site-packages/django/db/models/query.py" in get
  305.                     % self.model._meta.object_name)

Models :

class InheritedProfile(models.Model):
    pid = models.CharField("PID", max_length=11, blank=True, null=True)
(...)
    class Meta:
        abstract=True

class UserProfile(InheritedProfile):
(...)
    user = models.ForeignKey(User, unique=True, related_name='profile')

class Friend(InheritedProfile):
(...)
    friend_of = models.ForeignKey(UserProfile, related_name='friend_of')

Forms :

class FriendForm(forms.ModelForm):
    pid = forms.RegexField(regex=r'^\d{11}', max_length=11 ,widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=50)))
(...)    
    class Meta:
        model = Friend
        exclude = ( 'friend_of', )

    def clean_pid(self):
        try:
            user = UserProfile.objects.get(pid=self.cleaned_data['pid'])
        except User.DoesNotExist:
            try:
                user = Friends.objects.get(pid=self.cleaned_data['pid'])
            except Friend.DoesNotExist:
                return self.cleaned_data['pid']
            raise forms.ValidationError(_(u'User is somebody's friend.'))
        raise forms.ValidationError(_(u'User with given PID already registered.'))

    def save(self, user, *args, **kwargs):
        self.instance.friend_of = user                           
        post = super(FriendForm, self).save(*args, **kwargs)
        post.save()
        return post

Views (not sure if they’re needed):

def add_friend(request):
    userprofile = UserProfile.objects.get(user=request.user)
    count = 0

    if request.method == 'POST':
        form = FriendForm(request.POST, request.FILES,)
        if form.is_valid():
            count = Friend.objects.filter(friend_of=userprofile).count() 
            if not count > 5:
                form.save(user=request.user)            
                next = reverse('user_profile',)
            else:
                msg = "You already have 4 friends"
                render_to_response('user/data_operations/error.html', {'msg': msg}, context_instance=RequestContext(request))
            return HttpResponseRedirect(next)
    else:
        form = FriendForm()
    return render_to_response('user/data_operations/add_friend.html', {
            'form':form, 'user':request.user,
            }, context_instance=RequestContext(request))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:29:38+00:00Added an answer on May 15, 2026 at 4:29 pm
    try:
        user = UserProfile.objects.get(pid=self.cleaned_data['pid'])
    except user.DoesNotExist:
        ...
    

    It’s because you try to get UserProfile object but check for user object DoesNotExists, not UserProfile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android app where I've extended the base Application class in order
I have developed a Facebook application that runs inside an iframe in the Facebook
I previously have an FBML application in Facebook and now change to an IFrame
I am developing a facebook application. I am not sure about getting extended permission
I am trying to create a timesheet application in MVC 2, but I feel
I would like my MVC application to check (on every request) if the current
Ok so I have an android app with an Activity (UI) and a Service
I'm a refugee from the old Facebook Developer Toolkit porting my app to the
We are in the process of working on our second generation of our eCommerce
I'm building a solution for a client which allows them to create very basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.