Using the Django admin for the Admin website - python

We have a project in which we have to use 3 different backend frameworks/programming language and integrate them together to form one correlated website: Java(Spring MVC) for the customer end website, PHP(CodeIgniter) for the service provider website, and Python(Django) for the admin site.
My question is, can I use the admin site of Django alone? I will only use it for accepting user registrations, deactivation, and tracking transactions. So it's all just going to be basic CRUD functions for the database. Or is there an alternative framework for me to use? Thank you.

You'd need to define Models for the objects / tables used by other frameworks (which should be possible using Model Meta attributes to map it to an existing table name: https://docs.djangoproject.com/en/1.11/ref/models/options/).
The options you'll definitely want to use are db_table='existing table name' and managed=False (to tell Django not to prepare migrations for this table).
But as long as you can get a working Django Model that can interact with the tables for the other backends you should be able to read / update those records with the Admin interface just as if they were native Django models.

Related

Django ArrayField on Frontend Form?

I'm currently in the process of rebuilding my WordPress website into a full Django web app. With WordPress, I had made great use of the awesome Advanced Custom Fields plugin, and I'm struggling to get the same functionality with Django. One field in particular with ACF is called a "Repeater Field" that lets me click a button to add another row to an array.
I did manage to get something similar working with Django, but only in the Admin part. I've used this plugin "Django Better Admin ArrayField" - https://github.com/gradam/django-better-admin-arrayfield and it displays the arrayfield exactly as I want:
Django Better Admin ArrayField
How can I get this to work on the frontend of the site, like in a user-submitted form?

Migrating to Django rest framework

Currently, I am using node as backend and looking forward to shift my project to django-rest-framework. In node I used firebase-auth and MySQL and have a table called FIREBASE_USERS with email and firebase_uid fields. I was thinking of building my own custom auth for drf but can't figure out on using my FIREBASE_USERS table instead of django Users model. I read that django provides settings. AUTH_USER_MODEL to set your own custom model but the documentation uses AbstractUser class to create that and I don't want to mess with my tables since the tables are used in other projects too. Any suggestions would be appreciated.
Your custom user model needs to contain the properties as described in (1). AbstractBaseUser is a shortcut to achieve this. Override the Meta.db_table to match you table name. If this is somehow not sufficient, consider creating your own authentication backend as described in (2) and create a django user with a foreign key to your firebase user. But in order to let django function properly your user model needs to have the methods as described in (1).
Maybe (3) solves your problem?
(1) https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#django.contrib.auth.models.CustomUser
(2) https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#writing-an-authentication-backend
(3) https://github.com/fcornelius/django-firebase-auth

Create an estimator tool in Django Python

I am new to Django. I have read the official documentations and managed to create models in Django. I have a task to create an estimator tool that could provide the estimate(cost) to the user when he selects the hardware/softwares etc. This could be something similar to this http://calculator.s3.amazonaws.com/index.html. This is only for reference but I want to add details dynamically.
Basically I am curious to know about:
How to add rows in Django?
How is the 'Monthly cost' working in amazon calculator?
I want to achieve something similar to this dynamic estimations.
Any pointers/articles/suggestions will be helpful in my learning and analysis.
You have to override the Django admin template for that.
How to add button next to Add User button in Django Admin Site
for auto-selecting the group value you can use
https://github.com/crucialfelix/django-ajax-selects

Django admin changelist view used in the users site

Basically the admin changelist view has a lot of nice features like sorting, filtering, field list, pagination...
Can I borrow that functionality and use it in my public users site? I was thinking to have class-based view called Cars and borrow all those features from the admin site.
I thought that ModelAdmin would be a place to look, but I have no idea to implement that.
The django-table2 app is more reasonable option for such task than the admin's changelist.
Actually I ended up using django admin for this site instead of developing a public site. Plus on top of this I used django-grappelli to customize the dashboard and make it look like a custom site.
So now I have two admin sites:
1- is the default django/grappelli site that has all the links and functions of the traditional admin site. and this was only used by developers and super users
2- a custom admin site called dashboard that looks more user friendly, and have customized all the look and feel, plus it has the change list, change form of my models so I don't have to rewrite these functions.
and this is how it looks now:

Python / Django multi-tenancy solution

I could use some help creating a plan of attack for a project I'm working on.
Imagine that the site is for a group that oversees regional sales offices, distributed around the world. The purpose of this project is to let superusers spin up a new sub-site specific to each and every office, at a fast pace -- sites are added on a frequent basis. The office sub-sites should be wholly contained with "admin" users specific to that sub-site and should be user-friendly CMS. A superuser should be able to step in and manage all of these office sub-sites.
In addition to the self-contained office sub-site instance, there is also a need for each sub-site to manage contacts, leads, etc and store this in one central area for the superusers.
I've done a few sites using Django, but never anything multi-tenant. I'd like suggestions for technologies to use or tutorials/documentation that might be helpful.
Requirements:
Each sub-site uses the same source (templates, JS, available features, etc), but can be modified to reflect custom content within the templates.
Assigned subdomains (with an option of using a fully qualified domain) per sub-site, configured within the project, not in a hardcoded settings file.
Sub-site specific user access controls, in addition to superusers who can access all sub-sites.
The ability to provide an "independent" CMS for each sub-site. i.e., A sub-site admin only sees their content. My preference for this project would be django-cms, but I'm open to suggestions.
Support for apps that pool the data from all the sub-sites, but limit sub-site "admins" to only viewing their records into that app.
Considering the above, what approach would you recommend? I am open to reconsidering technologies, but I would like to stick with Python.
There is a great app called django-tenant-schemas that uses PostgreSQL schemas mechanism to create multi-tenancy.
What you get is specyfing SHARED_APPS that contain objects shared across all the schemas (sub-sites), and TENANT_APPS that contain objects specific for a sub-site, i.e. users, records etc. The schemas are completely isolated from each other.
Each PostgreSQL schema is tied to a domain url, so that middleware checks the HOST part of the request and sets the db connection's schema to appriopriate one.
In addition, it allows you to define a PUBLIC_SCHEMA_URLCONF which allows you to specify urlconf file for public schema - the meta site that is not tied to any sub-site.
Sorry for quick and dirty answer, i just share what i've done to achieve multi tenancy:
django-tenancy I like the author's approach of using "dynamic model"
django-dynamicsite This is where dynamic SITE_ID based on domain will be linked to a tenant
Both libraries above, when combined, is able to serve a django instance which is multi-tenant, and flexible. What i mean flexible here is: you can define any model whether is it "tenant" or "global". So, you can have a site with global user but per tenant product catalogue, or per tenant + product. From many django app i've tried, this is the most flexible way to achieve multi tenancy
The Django based CMS Mezzanine also has multi-tenancy support.
It has most of the features you requested except the sub-site user controls I think. The admin page can be separated by site for admin users, but the normal users not.
However, if you dont need a CMS this might be an overkill for your use-case, But I wanted to mention it here for completeness.
I have been trying to use django-tenants for a while along with Wagtail but this combination didn't work very well, or let me say, despite of a lot of try I was not able to get wagtail admin-page working correctly. I think will try to switch to django-tenant-schemas which I more widely used .
NOTE: django-tenant-schemas is not maintained now.

Categories

Resources