I'm nearly done with my Django app and I was wondering if it's to create a custom page where the app user admin will be able to cahnge one-off overall app settings like language, timezone, currency, URL slug, app limits (e.g. Max number of xyz, default abc etc) etc Is this possible? Feel like I'm missing a trick here. Any advice or resoucrces would be great.
Related
Is there a way to deploy Django Admin and your main application separately, though both of them sharing the same Models / Business logic services.
I come from Grails background where you can create a plugin which can hold your Entities and common business logic and that plugin can be utilized by other application deployed and scaled separately though using the same Database. You don't have to repackage your plugin again for every change rather its just sibling folder to your other projects.
Can I achieve something similar with Django?
Assuming a typical setup, in order to be useful Django Admin needs access to project's apps and their models.
So a setup that you've described would require at least:
simple URLconf with just Django Admin
models and their Admin bindings for all apps that need Admin
settings with database credentials
Even if your models and Admin bindings are not dependent on other parts of the codebase,
extracting the above components to a separate project and then keeping everything
in sync sounds pretty hard.
Summarizing: I would say it's hard but possible if it's something that you really need,
but Django Admin hasn't been designed with such use case in mind.
Django admin is actually separate from the main application by placing it on its own url. Even if they know the admin url, users cannot log in to the site's admin unless they have already been assigned Staff status via the admin. You can set the admin prefix to anything you want, so if you want to "hide" the admin login page, just make it something long and random (good for security too), and basically no one but those you tell will even know where the admin site can be found.
Django 1.11
If I click Groups in Django admin site, I can see a list of groups. Namely, the address is http://localhost:8000/admin/auth/group/
I monitor the CPU usage in terminal. Python is consuming 4-5 % now.
I have organized 4 groups. So, if I click any group, the server just calculating something for several minutes. The address now is like http://localhost:8000/admin/auth/group/6/change/
Maybe about 5 minutes the server is calculating something. And Python is now consuming 100 % of CPU resources.
Well, Django admin is analyzing something.
I have about 23-25 models. Well, this is not a very big number of models.
Each model is 3 standard permissions (add, change, delete). And I created one permission myself in the Meta class of a model.
So, as soon as "Change group" page is in front of me with available permissions and chosen permissions, CPU consumption by Python is again 4-5 %.
Could you comment on this? Is it curable?
Came across this issue when using django debug toolbar with the built in django admin app. The change/update page was incredibly slow locally (sometimes it would not load at all) but if I set DEBUG=False (thus turning the debug toolbar off) it worked as expected. In my particular case, I didn't need the debug toolbar for the admin app so I disabled it for only those admin URLS like so:
# settings.py
DEBUG = True
def show_toolbar(request):
# disable debug toolbar for built in admin app urls only
if request.path.startswith('/admin'):
return False
else:
return True
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar,
}
We're using the same setup as Max Malysh:
Django 1.11
A custom User model based on django.contrib.auth.models.AbstractUser
The custom user model set in the settings via AUTH_USER_MODEL variable
We've got the same issues and I think I found the issue, or at least the module which is causing the delays. It has nothing to do with Django and/or the DEBUG mode itself, because I think the issue is within the debug_toolbar.
If you deactivate the debug_toolbar application and debug_toolbar.middleware.DebugToolbarMiddleware middleware, it works like a charm.
I didn't had the time to reverse-engineer it, but I'll have a look at it when I find the time. In the meantime and as a workaround, deactivate the debug toolbar if you don't need it.
Sorry, it's not a final solution yet, but I thought I'll share my findings in case they can help somebody.
Cheers
Domi
EDIT/UPDATE: It has something to do with the Template panel of the Debug Toolbar. If you deactivate it, you'll have a much faster response time!
I've encountered the same problem when adding a new group with Debug=True in settings.py.
The same code works fine with Debug=False.
Some background information:
We use Django 1.11
We use custom user model inheriting from AbstractBaseUser
There are ~30 models registered on the admin site
Django debug toolbar output:
I was experiencing this same problem, but probably for a different reason than the OP was.
If you have a large number of Users, look at your admin.py and make sure that you are not displaying Users inline on the Group admin page. That can cause very slow loading of the Group admin page if the Group has a large number of users in it.
I want to use Django for a web application I'm building that will have an admin panel. I know that you need to just activate the admin app and you're ready to go. However, I would like to have a custom panel, I mean, I want to design the layout myself, I want to add menus and forms for the admin to insert new data in the database etc. Is it possible? or I should write a similar application that will have such features?
For more control over the layout (custom menus etc.) you should check django-admin-tools.
And if you take a look at Django's docs you'll learn that you can easily tweak and override most parts of the admin. For example here is a demonstration on how to use a custom form:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin
So the admin is pretty customizable. But the question if you should build your own app or reuse the admin depends pretty much on your specific needs. At least make sure you know in which directions the admin can be easily bend.
The sole purpose for Django's admin is to allow you to manipulate (add/edit/remove) data in your database. I think you should at least try to check what the admin is capable of before trying to reinvent the wheel. You'll soon discover the level of complex insight the admin allows you to have. Then you'll discover that making it yourself is unnecessary excess of work and you'll end up with modifying a couple of admin-templates and CSS styles.
Yes, you can customize Django Admin Panel, Django provides some sort of customization for showing database tables structure from their own, for that you can follow DJANGO ADMIN SITE DOC , it will really help you.
For the customizations beyond the Django admin site settings, you can customize admin panel add manual layout, by adding manual detailing in Django template files which are stored in Django environment, django/django/contrib/admin/templates/admin/index.html of your current Django version. You can update its HTML, CSS, and JS according to need.
I tried to find a way to use the filter that gives the Django Admin in my applications, as you know by just adding "list_filter" in admin.py, to enter the Admin, our results can be filtered, I would like know if there are ways to use the same application but in my own projects
Thanks!!
You can use ListView and add a filter form to context. It's not like "add one line to admin class" but it does not need much time to do too.
Django has lots of magic in admin site because built-in powerful admin site is one of Django's killer features. So it works out-of-the-box without setting up static url and with only tiny admin module linking your models. But all this magic is not isolated and in most cases cannot be used outside the admin.
I am using django 1.2 to create a multi site shop. I need multiple admin logins for each shop instance, e.g.
site.com/au/admin
site.com/uk/admin
and so on.
I have a middleware class and a dbrouter that handles database connections based on the URL. This works fine.
I am trying to add some customisation per admin system based on what is available for that particular shop. So:
in admin.py :
if country == 'au':
admin.site.register(Orders)
admin.site.register(Payment)
if country == 'uk':
admin.site.register(Store_locator)
etc.
Hers's the problem: If I log into the AU version of the site the admin system displays the correct elements for AU. If I then log into UK, it still shows the AU version of the admin system, so the above code seems to only get used on the first load. if I kill the django server and restart it, then go into the different shop admin page, it will have reconfigured for that shop.
How I can get it to pick up a change in country each time the admin system loads? Why is this problem happening in the first place?
Any help would be greatly appreciated.
Thanks,
imanc
I'd bet that Django doesn't read the admin config on each request, but on each time the server is restarted - that's why it 'sticks' to whichever you accessed first.
Why not do something with Django.contrib.auth's permissions to limit what a particular admin user can see in the admin, and register all the models in admin.py as standard?