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 7890065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:15:26+00:00 2026-06-03T06:15:26+00:00

I noticed that you can’t have – , + , / , * ,

  • 0

I noticed that you can’t have -, +, /, *, or any other mathematical character symbol in the related_name. You also can’t use :, |, or ..

If you have any of the above characters in related_name, although Django’s models.py will validate, whenever you do a query lookup it’ll throw an error like

Q(userprofile.user__place__managers=user)
SyntaxError: keyword can't be an expression

The reason I want to use a special character is because I like to have my related_name in the form of {class_name}{field_name}. So for example for the UserProfile model class I would do something like

class UserProfile(models.Model)
    user = models.OneToOneField(User, related_name='userprofile-user')
    user_type = models.ManyToManyFields(UserType, related_name='userprofile-user_type')

That way when I do a query that involves a following a relationship backward, but still know how I am following it backward. For example, if I simply do

user_type = models.ManyToManyFields(UserType, related_name='user_type')

then I can access UserType from User doing User.objects.get(pk=1).user_type.all(). But this makes it looks like user_type is a field of User.

Instead if I could do something like User.objects.get(pk=1).userprofile-user_type.all() then I would know that I am going from User to UserProfile to UserType.

Well my way of thinking is probably in the minority and I would assume that most people would just do related_name='user_type' or maybe even use default user_type_set.

Another question would be: What is the good style for naming related_name?

  • 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-03T06:15:28+00:00Added an answer on June 3, 2026 at 6:15 am

    userprofile-user_type is not a valid python identifier.

    Python thinks you are trying to subtract user_type from userprofile.

    In your specific case profiles would be a good enough related manager name.

    So that when you have a a UserType instance:

    utype = UserType.objects.get(...)
    utype.profiles.all()
    

    It would give you all the profiles associated with that user type.

    Also there is no ManyToManyField*s*, remove the “s”.

    Try not to be more verbose than what is needed to convey the meaning of a relationship.
    The field name inside the related name is redundant and unnecessary.

    UPDATE:
    Please do not name it userprofiles_from_user_type

    It’s like having this:

    class Person:
        def PersonWalk(self):
            ...
    

    Instead of:

    class Person:
        def walk(self):
            ...
    

    Let me give you a more complex example with an intermediate table

    class Service(Model):
        name = models.CharField(max_length=32)
    
    class Person(Model):
        services = models.ManyToManyField('self', through='PersonServiceRel', null=True, related_name='friends', symmetrical=False)
    
    class PersonServiceRel(Model):
        provider = models.ForeignKey(Person, related_name='provided_services')
        consumer = models.ForeignKey(Person, related_name='consumed_services')
        service = models.ForeignKey(Service)
    

    Now let’s say we have people providing some kind of services to each other and I want
    to know if the user “rantaplan” provides “tracking” service and to whom.

    rantaplan = Person.objects.get(name='rantanplan')
    tracking = Service.objects.get(name='tracking')
    PersonServiceRel.objects.filter(provider=rantaplan, service=tracking)
    # or
    rantaplan.provided_services.filter(service=tracking)
    

    Note the PersonServicesRel the fields ‘provider’ and ‘consumer’ and their related_manager.
    Also note the necessary query. I think it’s quite readable.

    So I suggest that you name your fields and related managers depending on their purpose and usage, with as little verbosity as possible.

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

Sidebar

Related Questions

I noticed today that I can't use * to pass width or precision arguments
I have noticed in Java that you can have a function with object... as
I noticed that you can't throw an exception in a destructor. So my question
I'm new to RubyAmf. I noticed that you can send an object with RubyAmf
Is there a way to convert HTML into XAML? I noticed that you can
I noticed that various systems use various characters as the replacent for illegal ones
I have recently noticed that when i visit certain websites, there are usually links
I just noticed that the Zend lucene implementation has a default analyzer that can
We have noticed that our queries are running slower on databases that had big
I am new to C++ coding. I have noticed that if I enter multiple

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.