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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:31:56+00:00 2026-05-22T18:31:56+00:00

I have a simple userprofile class in django such that class Profile(models.Model): user =

  • 0

I have a simple userprofile class in django such that

class Profile(models.Model):
    user = models.OneToOneField(User,unique=True)
    gender = models.IntegerField(blank=True, default=0, choices=UserGender.USER_GENDER,db_column='usr_gender')
    education = models.IntegerField(blank=True, default=0, choices=UserEducation.USER_EDU,db_column='usr_education')
    mail_preference = models.IntegerField(blank=True, default=1, choices=UserMailPreference.USER_MAIL_PREF,db_column='usr_mail_preference')
    birthyear = models.IntegerField(blank=True, default=0,db_column='usr_birthyear')
    createdate = models.DateTimeField(default=datetime.datetime.now)
    updatedate = models.DateTimeField(default=datetime.datetime.now)
    deletedate = models.DateTimeField(blank=True,null=True)
    updatedBy = models.ForeignKey(User,unique=False,null=True, related_name='%(class)s_user_update')
    deleteBy = models.ForeignKey(User,unique=False,null=True, related_name='%(class)s_user_delete')
    activation_key = models.CharField(max_length=40)
    key_expires = models.DateTimeField()

You can see that deletedBy and updatedBy are foreign key fields to user class. If I don’t write related_name='%(class)s_user_update' it gives me error (I don’t know why).
Although this works without any error, it doesn’t push the user id’s of deletedBy and updatedBy fields although I assign proper user to them.

Could give me any idea and explain the related_name='%(class)s_user_update' part ?

Thanks

  • 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-22T18:31:56+00:00Added an answer on May 22, 2026 at 6:31 pm

    '%(class)s_user_update' implies that it is a string awaiting formatting. You would normally see it in the context:

    '%(foo)s other' % {'foo': 'BARGH'} 
    

    Which would become:

    'BARGH other'
    

    You can read more about python string formatting in the python docs. String Formatting Operations

    I can’t see how the code you have would ever work: perhaps you want:

    class Profile(models.Model):
        # other attributes here
        updated_by = models.ForeignKey('auth.User', null=True, related_name='profile_user_update')
        deleted_by = models.ForeignKey('auth.User', null=True, related_name='profile_user_deleted')
        # other attributes here
    

    If it does work, it is because django is doing some fancy magic behind the scenes, and replacing '%(class)s' by the class name of the current class.

    Notes on the above:

    • The consistent use of *snake_case* for attributes. If you must use camelCase, then be consistent for all variables. Especially don’t mix *snake_case*, camelCase and runwordstogethersoyoucanttellwhereonestartsandtheotherends.
    • Where you have two attributes that reference the same Foreign Key, you must tell the ORM which one is which for the reverse relation. It will default to ‘profile_set’ in this case for both, which will give you the validation error.
    • Use ‘auth.User’ instead of importing User into the models.py file. It is one less import you’ll need to worry about, especially if you don’t use the User class anywhere in your models.py file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my domain model I have following Classes.A 'UserProfile' has one 'SecurityPrincipal' class SecurityPrincipal{
I've made a simple user profile editor for a django project. And it has
I have a simple model like class Interest < ActiveRecord::Base has_and_belongs_to_many :user_profiles end class
I have simple win service, that executes few tasks periodically. How should I pass
I have simple WinForms application where modifying Windows Registry. The problem is that in
I currently have a model set up like so: I have a Test class
I've implemented a UserProfile model (as the Django 1.2 docs say is the proper
Greetings - I have a SharePoint 2010 server running with the User Profile service
I have a simple webapp in Django for an iPhone app. I want to
I have a simple function in which a user will click on a div,

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.