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

  • Home
  • SEARCH
  • 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 8816593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:39:22+00:00 2026-06-14T04:39:22+00:00

I am getting very strange error when I am using select_related. I have created

  • 0

I am getting very strange error when I am using select_related. I have created a model which extends the auth_user table. For your reference I am pasting the model below

class BasicDetails(models.Model):
   username = models.OneToOneField(User)
   name = models.CharField(max_length = 100, verbose_name = "Name")
   sex = models.CharField(max_length = 10, verbose_name = "Sex", choices = GENDER_CHOICES)
   dob = models.DateField(verbose_name = "Date of Birth")
   mothertongue = models.CharField(max_length = 20, verbose_name = "Mother Tongue", choices = LANGUAGES_CHOICES)

The above table has only one record and when I run the below query in the django shell its working fine and I am able to retrieve the values.

basicdetails = BasicDetails.objects.select_related('auth_user__username',request.user)

However when I input the same query in my views and template I am getting below error.

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111.response = callback(request, *callback_args, **callback_kwargs)
File "/home/vikramt/python/OpenMatrimony/wedding/views.py" in myprofile
160.basicdetails = BasicDetails.objects.select_related('auth_user__username',request.user)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py" in select_related
173.return self.get_query_set().select_related(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in select_related
686.obj.query.add_select_related(fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in     add_select_related
1759.for part in field.split(LOOKUP_SEP):
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in inner
185.return func(self._wrapped, *args)

Exception Type: AttributeError at /myprofile/
Exception Value: ‘User’ object has no attribute ‘split’

Can someone help me on this context. I couldn’t able to understand what was the problem. Any clues?

-Vikram

  • 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-06-14T04:39:23+00:00Added an answer on June 14, 2026 at 4:39 am

    select_related expects its parameters to be strings. Your request.user object is not a string, and don’t have a split() method. That is why an AttributeError is being raised.

    But the tricky part is that, as you said, when you did the same thing from inside a shell session, it worked. I would risk to say that in that shell context, request.user was somehow a string, or was behaving like a string.

    Anyway, why are you passing an User instance to select_related? I mean, what do you want to achieve by doing that?

    Edit

    Ok, if you want to retrieve the record of BasicDetails for the current logged
    in user, you should be using the filter method. It’s used to
    filter a queryset:

    basicdetails = BasicDetails.objects.filter(username=request.user)
    

    The select_related method is used to tell the ORM to do something
    like a SQL join to populate the specified related columns of the results.

    And I would recommend you to rename your username column to
    something more clear. It’s a relation to the user table, so you should call it
    just user.

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

Sidebar

Related Questions

I have just started getting a very strange error when using jQueryMobile for my
I'm using Kohana 3.1 and I'm getting a very strange error. The Kohana POST
Using the standard add record code I am getting a very strange error when
I'm getting a very strange error. In my XAML I have two MediaElement tags
I'm getting a very strange error, I've created a user 'testuser' with the following
Very strange error I have, I am getting request as null when I try
I'm getting a very strange error with preg_replace. I'm using the following code: $text=preg_replace('/(\s)?'.preg_quote($f).'(\s)?/','<a
I am getting a very strange error in my code. This assignment is for
I'm getting some very strange behaviour using the following switch statement: string recognise_mti(int mti_code)
I'm getting a very strange error while trying to read from a simple text

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.