Python Django: Customize Admin Startpage as analytical Dashboard - python

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!

Related

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.

Can I use DRF to create a page based site (e.g. a blog)?

Can I use Django Rest Framework to create an "ordinary" site - like a blog, with templated HTML pages ala "normal" django?
The reason I ask this is that I am building a website (sort of a blog), but for sections of the site, the functionality will be provided by making CALLS to a REST API.
So, my question essentially is this:
Is DRF equivalent to (all the features/functionality of django) + ability to create/use RESTful APIs?
Django Rest Framework is an add-on to Django. It doesn't replace Django; it's just another app. You still create your models via Django, and can use views and templates as normal.

where do I place simple pages in a django application?

I new in django, but I am really old in web developpement.
My question is about how to properrly organize your project into a django project. I am about to build my first web site in django and i have the following question :
I want a contact page in my website? basically it's a form/view/template, but where do I create that ? should I create a whole new app?
Django projects deliver functionality through apps. A project is the configuration holding your chosen apps together. It's highly likely you'll need to write at least one app yourself. Your app will have models, views and forms.
There are a number of projects that can help bootstrap your project. See the matrix on djangopackages.com related to boostrapping.
Pinax is a good application bootstrapping tool providing a standard project layout, starter projects, reusable apps and default templates.
The authors of Two Scoops of Django have a layout on GitHub which is focused on the environment and file/directory layout.

What is the fastest way to generate CRUD webpages for Google App Engine using Python?

I have created a set of Models for my database using Python. Now I'd like to rapidly load them with some data -- manually. If this were a .NET app, I'd use one of the nifty controls that come with Visual Studio to rapidly connect to the database and bind a grid to it. Then go to town adding data.
What's the matching way to do this in Python using Google App Engine?
In ASP.NET MVC, they have this new "scaffolding" stuff (part of Entity Framework) that will generate CRUD pages for you. Is there anything like that given a bunch of Model objects in GAE?
P.S. using the handy, dandy command line options --use_sqlite and --datastore_path, I can quickly backup my database in my dev environment once I do this.
If you are using Django on GAE then you can use the Django Administration site:
So what’s Django’s approach to these boring, repetitive tasks? It does
it all for you—in just a couple of lines of code, no less. With
Django, building an admin interface is a solved problem.
It automatically builds CRUD based HTML forms for managing the model.
Have a look to the appengine admin project.
Appengine Admin is simple python package that you can use for creating
automatic admin interface for your Google Appengine application.
Here is a screenshot:
and here is the quickstart tutorial.
After creating your models, simply adding this line of code:
# Register to admin site
appengine_admin.register(..your list of class Models definition)
and after have defined the proper route to the admin with:
(r'^(/admin)(.*)$', appengine_admin.Admin)
you can access to the customized admin that offers the following features:
List records for each registered model
Create new records
Update/edit records
Delete records
I'm still something of a python and GAE newbie, but I've been working with it a lot over the past few months so you might find that this works:
You can use Model.properties() to get the list of properties for the model in question and save it to a list. You can then add the list to the context dictionary for use in your template. In your template iterate over the loop to generate a basic list of input fields with the names matching each property.
{% for tItem in list %}
<input type="text" name="{{ tItem }}" />
{% endfor %}
Then you can post back to the same page, where you can use Request.arguments() to pair your object properties to your model for saving into the datastore.
To my knowledge there's not a much more elegant solution than that, at least not comparable to the ASP.NET MVC scaffolding that you're talking about.
(disclaimer: I've not actually tried this so there is likely a problem or two that needs to be sorted)
The trouble with Django on App Engine is you can't use the GAE datastore and ndb models (so the Django admin is not available), or you have to start using a hacked version of Django: http://django-nonrel.org/
Well probably for most apps you're better off using Cloud SQL anyway, which is basically MySQL so no prob with Django.
If you need to use the GAE datastore try this framework, which provides a CRUD admin:
http://ferris-framework.appspot.com/docs/index.html
You can check out Ferris Framework
which is tightly integrated to Google App engine and datastore.
Ferris Framework also has the scaffolding component for creating CRUD actions in a breeze.
http://ferris-framework.appspot.com/docs/users_guide/scaffolding.html?highlight=scaffolding

Django - managing multiple pages with multiple fields

I am using Django for developing a website and I want to allow my staff to be able to add/edit/delete pages with multiple text fields. I am planning to use Django's admin framework for this as the staff is a non-technical one.But I have no clue on how to go about doing this so that people can login and edit the contents on these pages whenever they want.
Also, my site will be receiving around 1500 hits per day. I don't want to embed these pages in static templates (so that I can allow my staff to edit it). Will loading this data at runtime slow down my site. I am using a Servint VPS server.
Thanks
niting
Follow the Django tutorial, replacing the concept of Polls with Pages, and Choices with Content blocks and you'll be most of the way there (Django's built in Admin will allow you to edit these models).
For a more advanced CMS based on Django take a look at either Django CMS or FeinCMS.

Categories

Resources