admin specific app in django

306 Views Asked by At

I'm using Django 1.11

I want to create an admin specific app which is only accessible by admin interface.

I want to create an app to add country and state records which can be added or edited only by Admin from /admin.

Also, these records can be used by any application to populate a select field in adding a record like address.

If I create country app in mydangoapp/country and add URL to mydangoapp/mydangoapp/urls.py then it can be accessed by other users too by www.example.com/country which I don't want.

Where to create a model for this? Is it possible to create an admin specific app only?

2

There are 2 best solutions below

1
On BEST ANSWER

Every app can be used only as admin specific till the time you don't give a urlpatterns for that app to be accessed by users.

So, you just create an app, make models, register them. But don't write views, forms and urls for that app.

0
On

In your case you should do something like that in your mydjangoapp urls.py:-

from country import views as country_views
urlpatterns = [
              url(r'^admin/custom_prefix/country/', include('country.urls')),
              url(r'^admin/', admin.site.urls),
]

Make sure u enter it in this order(i.e. before the r'^admin/' regex) in urlpatterns list. Hope this solves your issues :-)