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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:06:42+00:00 2026-06-11T18:06:42+00:00

New to Django here, found this function in the user profile model of code

  • 0

New to Django here, found this function in the user profile model of code someone passed to me, but I can not for the life of me find it in the documentation, nor can I find it anywhere else in his code. But everything including user authentification seems to work, so not sure where this is create_new_user_and_profile is coming from? Also, not sure if this is the best way to do users, can anyone give some tips?

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)


class UserProfile(models.Model):
    user = models.OneToOneField(User)
    office_number = models.IntegerField(null=True)

    def initialize_static_fields(self, office_number):
        user = models.OneToOneField(User)
        self.office_number = office_number

    def create_new_user_and_profile(username, email, password, office_number):
        u = User.objects.create_user(username, email, password)
        u.get_profile().initialize_static_fields(office_number)
  • 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-11T18:06:43+00:00Added an answer on June 11, 2026 at 6:06 pm

    The user model has a create_user method, however it does not create a profile by default, you could use a signal to create a profile each time a new User is created, e.g.

    def create_profile(sender, instance, created, **kwargs):
        profile = None
        if created:
            profile, created = Profile.objects.get_or_create(user=instance)
    
    post_save.connect(create_profile, sender=User)
    

    The method added to your model is a custom method which creates a user and triggers create_user_profile, which is then complemented with extra info. IMO, this method should not be part of the CalscopeUserProfile and likely belongs in a (form)view (private) or service function.

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

Sidebar

Related Questions

I have found here on stackoverflow a solution to extend django-registration with new fields
I'm creating a user profile class for my new django website, and I am
I'm new to Django, and try to develop my resume online. Here it is
I create a new Django app (not project) called Bussinesses, then add following class
While I am studying the new django docs on class-based views, I notice this
I'm new with Django + Ajax. My Problem is I can't get the value
I'm new to Django but am working on the tutorial on the Django website
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
Beginner at Django here, I've been trying to fix this for a long time
My django model looks like this: class Entity(models.Model): name = models.CharField(max_length=40) examples = models.ManyToManyField(Example,

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.