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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:49:47+00:00 2026-06-15T19:49:47+00:00

I successfully extended some admin model and form, but I’m not sure how to

  • 0

I successfully extended some admin model and form, but I’m not sure how to keep my file tree clean.

If I put forms.py at the same level as admin.py, everything work perfectly:


forms.py

class MyUserCreationForm(UserCreationForm):
    #...

class MyUserChangeForm(UserChangeForm):
    #...

admin.py

from myapp.forms import MyUserCreationForm, MyUserChangeForm

File tree

mypackage/
    admin.py
    forms.py

Now, in order to have my admin-related forms separated from the other forms and make the code cleaner, I added a folder admin to put my admin-related forms. In that case URLs seem to be messed up. When going to /myapp/admin/ I get the default admin page, not the one I customized in my admin.py.

admin/forms.py

class MyUserCreationForm(UserCreationForm):
    #...

class MyUserChangeForm(UserChangeForm):
    #...

admin.py

from myapp.admin.forms import MyUserCreationForm, MyUserChangeForm

File tree

mypackage/
    admin.py
    admin/
        forms.py

I guess the system is confused because admin is both a file and a folder. What’s the standard way to keep custom admin-related files in Django?

EDIT: in the case shown above, there is a conflict between admin.py and the folder admin. I tried to put admin.py and forms.py in a folder, but it still does not work:

admin/forms.py

class MyUserCreationForm(UserCreationForm):
    #...

class MyUserChangeForm(UserChangeForm):
    #...

admin/admin.py

from myapp.admin.forms import MyUserCreationForm, MyUserChangeForm

class MyUserAdmin(UserAdmin):

    form = MyUserChangeForm
    add_form = MyUserCreationForm

    list_filter = ()

    fieldsets = (
        (None, {'fields': ('username', 'number', 'password')}),
        (_('Personal info'), {'fields': ('first_name', 'last_name')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff',)}),
    )


    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'number', 'password1', 'password2')}
        ),
    )


admin.site.register(MyUser, MyUserAdmin)

File tree

mypackage/        
    admin/
        forms.py
        admin.py

urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
  • 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-15T19:49:48+00:00Added an answer on June 15, 2026 at 7:49 pm

    Firstly, you need to create an __init__.py file in your admin directory in order for it to be treated as a package.

    mypackage/
        admin/
            __init__.py 
            forms.py
    

    The __init__.py file is often empty. See the Python docs on packages for more information.

    Secondly, you cannot have a directory called admin and a file admin.py. When you run import myapp.admin, python will ignore the admin.py file, and load admin/__init__.py instead.

    One possible solution is for you to move admin.py to admin/__init__.py. Then the following imports should work properly.

    # in e.g. your urls.py
    import myapp.admin # imports admin/__init__.py
    
    # in e.g your admin/__init__.py:
    from myapp.admin.forms import MyUserCreationForm, MyUserChangeForm # imports admin/forms.py
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've successfully extended python with C, thanks to this handy skeleton module . But
I read many pages but, i'm sure, I did some errors somewhere and I
I've successfully extended some SASS functions with Ruby code (http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions), and my extensions are
Successfully used jquery-infinite-carousel in the past but for my current project I need it
I successfully compiled ActionBarSherlock in Eclipse. But I get 75 errors when I use
I successfully installed the latest QuantumGrid from DevExpress, but I've never worked with this
I have successfully integrated the three20 framework in my project, and I have extended
i successfully integrated my .NET Dll into MATLAB. Everything is good. But, i pass
I've successfully used the AccountManagement code to retrieve basic AD information but it's only
Do you know some real examples of implementation and real use of extended XLink

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.