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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:52:53+00:00 2026-05-13T05:52:53+00:00

In my application, I have models that have the Users model as a Foreign

  • 0

In my application, I have models that have the Users model as a Foreign key, eg:

class Doctor(models.Model):    
username=models.ForeignKey(User, unique=True)
...

In the admin site, when adding a new Doctor, I have the option of adding a new User next to the username field. This is exactly what I want, but in the dialog that opens, it asks for a username and password for the new user; I would also like to be able to assign a group to this new user. What would be the best way of doing this ?

Thanks,
lokharkey

  • 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-13T05:52:53+00:00Added an answer on May 13, 2026 at 5:52 am

    In your application, create an ‘admin.py’, where you actually register your own model to admin, add following code.

    from django.contrib.auth.models import User
    from django.contrib.auth.admin import UserAdmin
    from django.contrib.auth.forms import UserCreationForm
    
    class MyUserCreationForm(UserCreationForm):
        """
        A form that overrides the UserCreationForm
        """
        class Meta:
            model = User
            fields = ("username", "groups")
    
    UserAdmin.add_form = MyUserCreationForm
    
    admin.site.register(Doctor)
    

    Now you just need to override the template that render this overridden form.
    Create a directory structure as,

    "your_project_root_directory"/templates/admin/auth/user/add_form.html
    

    and copy the content as,

    {% extends "admin/change_form.html" %}
    {% load i18n %}
    
    {% block after_field_sets %}
    
    <p>{% trans "First, enter a username and password. Then, you'll be able to edit more user options." %}</p>
    
    <fieldset class="module aligned">
    
    <div class="form-row">
      {{ form.username.errors }}
      {# TODO: get required class on label_tag #}
      <label for="id_username" class="required">{% trans 'Username' %}:</label> {{ form.username }}
      <p class="help">{{ form.username.help_text }}</p>
    </div>
    
    <div class="form-row">
      {{ form.password1.errors }}
      {# TODO: get required class on label_tag #}
      <label for="id_password1" class="required">{% trans 'Password' %}:</label> {{ form.password1 }}
    </div>
    
    <div class="form-row">
      {{ form.password2.errors }}
      {# TODO: get required class on label_tag #}
      <label for="id_password2" class="required">{% trans 'Password (again)' %}:</label> {{ form.password2 }}
      <p class="help">{% trans 'Enter the same password as above, for verification.' %}</p>
    </div>
    
    <div class="form-row">
      {{ form.groups.errors }}
      {# TODO: get required class on label_tag #}
      <label for="id_groups" class="required">{% trans 'Groups' %}:</label> {{ form.groups }}
      <p class="help">{% trans 'All existing Groups listed here. If you are not seeing any group, means you dont have any groups object created.' %}</p>
    </div>
    
    <script type="text/javascript">document.getElementById("id_username").focus();</script>
    
    </fieldset>
    {% endblock %}
    

    And you are good to go. Its working snippet.

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

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer >>> t1 = ("A", "B", "C") >>> t2 = ("1",… May 13, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer If you want to send updates to Twitter using their… May 13, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer Found it! I have to subtract the 16 bytes salt… May 13, 2026 at 4:31 pm

Related Questions

As a software engineer, I sometimes use Poser Pro to create artwork to insert
Over the last few weeks I have been studying the MVC design pattern for
I'm building an app in Ruby on Rails, and I'm including 3 of my
I'm currently in the planning phase for a project of mine. I thought about
I've never came across an app/class like Zend Search Lucene before, as I've always

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.