How to show entire existing postgres database in Django admin view - python

I have an existing PostgreSQL database and I'd like to browse it within Django's admin view. How do you make all the existing tables in a database browsable in Django's admin view?
I tried following the steps here but I was only able to view Groups and Users. I also read that maybe I have to edit admin.py but I'm not sure where that file would be located and what I'd have to put in it.

You need to tell Django which tables you want to browse in the admin view.
To manage database tables Django uses models. Your Django project should be divided into multiple apps and each app has its own modules such as models.py, view.py, admin.py etc.
So if you want to browse all the tables you need to add admin.py files in every app and in each admin.py file add the following lines to register the model with Django's admin.
from django.contrib import admin
from <your_app>.models import <your_model1>, <your_models2>
Now for each model that you imported add.
admin.site.register(<your_model1>)
admin.site.register(<your_model2>)
Please note that only those tables will be visible in Django admin which are managed by Django models. If you do not have a corresponding model for a table in your database you won't be able to view it in the admin.
To know more about the how the admin works read the Django documentation for your version of Django here. Also here is a good tutorial on configuring the admin view in Django.

Related

Python Django: Customize Admin Startpage as analytical Dashboard

I am currently developing a mobile app using Ionic and I am using Django Admin Interface as sort of Backend for adding and editing the content of my mobile app through a MySQL Database.
I currently wish to create a custom analytical dashboard for tracking the usage of the users of my mobile app in the startpage of the Django Admin. While there are some analytical packages for tracking the usage in Django, they only function for web applications.
In my case I need to gather and display aggregate data from my database (Django models & not Django models) as well for other APIs. Is there a way how can I fetch data in form of SQL queries and display them in my dashboard using Python (Django)?
And how can I extend the starting page of Django Admin to a full analytical dashboard with the named functionalities?
I am currently struggling with this as I am new to Django. Any help is much appreciated!
There are some prebuilt admin themes which you can look into, and I personally recommend Django Jet. You can also change directly the way that the admin templates are made and rendered looking around the contrib/admin folder on your Django installation, or you can extend the admin views and templates, take a look at the documentation. Hope I could help!

i need help and advice about django admin

I'm new with python and Django. I know a lot about the Codeigniter framework and there if you want to create a project like an eCommerce you must create an admin panel with template and function for the backend.
when I was creating backend I was adding functions for the admin panel where all functions were for adding some informations in the database.
so when I start with Django I saw that there was an integrated admin panel which can be modified but I have a question can I create app for Django which will be admin panel of my project and can I deactivate or delete integrated admin panel or can I add some functions and redesign integrated one
Yes you can "deactivate" the admin site. The easiest way would be to just remove the admin site url from your urls.py file. E.g (for my stock database) remove this line:
path('stock/admin/', admin.site.urls)
Yes, you can "deactivate" the admin site. The easiest way would be to just remove the admin site URL from your urls.py file.
E.g (for my stock database) remove this line:
path('stock/admin/', admin.site.urls)

Overriding Django admin vs creating new templates/views

I am a total noob with Django, I come from the PHP world and I am used to doing things differently.
I'm building an app and I want to change the way the backend looks, I want to use Bootstrap 4 and add a lot of custom stuff e.g. permission based admin views, and I was wondering what is the best practice, or how do more experienced django devs go about it?
Do they override all the django.contrib.admin templates, or do they build custom templates and login/register next to it, and use the django.contrib.admin only for the superuser?
What is the django way?
Django admin is intended for administration purposes. For all intents and purposes it is a direct interface to your database. While I have seen some people building customer facing interfaces using admin, this is most definitely not the way to make a general Django web application.
You should define views for your models. You can use built-in APIs to login and authenticate users. You should most likely restrict access to admin to internal users only.
As for templates, the modern way of doing things is to dynamically fetch data using an API and do all the UI logic in Javascript. Django can be used very well to provide an API to a frontend. Look into Django REST Framework. The basic idea is to write serializers for your models and have view functions serve the serialized data to the front end.
You could go the old school way and render your pages using templates of course. In that case your views would render templates using data provided by your models.
Yes. The admin pages is actually for administering the webpage. For user login and registration you create the templates. However, if you want your backend to look different then you can tweak the template for the admin page, admin login page as well. And you can also have permission based admin views. It's okay to over ride the defaults as long as you know what you're doing. Hope that helped.

Modifying django admin site to accommodate mongodb

I have read some posts such as
Django admin site with mongodb
. However, most posts are extremely outdated (like using django 1.3) and links fail to open. So I decided to repost.
I am using django 1.8 and I am trying to make the django admin site display my collections in mongodb just as it would for relational databases. I use mongoengine for ORM so I have classes in models.py to correspond to mongo collections. My mongo collections all have a predefined structure and doesn't contain Listfields that would confuse the django admin site. How should I go about modifying the django admin site to make it accommodate mongodb?

Separate Django Auth Database...Different Table Name?

I'm in the process of setting up a custom blog app using Django, with Mezzanine as the blog, which will be communicating with the auth system on my other Django app to handle all user authentication.
So far, I have set up an AuthRouter exactly like the example described here: Multi DB Setup in Django
However, my other Django app has a custom AUTH_USER_MODEL defined in its settings file.
As a result, when attempting to login to the blog, it is looking for a table with a different name from auth_user. I'm wondering if there is a way to specify the auth user table?
Thanks for any advice!
You need to have the code for your custom User model (or similar) in the blog project also. The you can set the proper table name with db_table (if auto generated is different). Then you will set AUTH_USER_MODEL in your second project to point to your custom model defined in the same project. You also need to modify your router to work with this custom user model.

Categories

Resources