How import between multi-site Django projects - django

How can I import models and views from Django Site1 to Site2 using the Sites Framework?
Django Sites Framework scenario
top
----site1
----site2
----media
#File on Site 2: views.py
from site1.article.models import Model1, Model2

Django's sites framework is about sharing the same code on different sites (in the end different Django instances with one codebase and one database).
Your directory structure suggests that you are doing it wrong: you should not have multiple site apps, putting your stuff in site1 and importing it into other site apps.
Instead you should code your Django Apps with the help of the sites framework:
add a site reference to your models where it makes sense
setup multiple Django instances each with its own SITE_ID in settings.py
your model objects can then be filtered by Site.objects.get_current()
You can do this in elaborate ways (Model inheritance, custom Managers for automatic filtering), but this is the basic description.

Related

What is difference between the admin panel and app in django?

I have a dummy project, I have been told to create the admin panel of this project.
I don't understand what the admin panel is and what an app is in a django project.
I saw a project in which there were 3 or 4 apps and the admin panel, how are these correlated?
The django admin app is a pluggable application built into django that allows you to easily generate an interface where users with staff accounts can create, edit, delete, and view content.
The django admin itself is an app. The django documentation defines an application as:
The term application describes a Python package that provides some set of features. Applications may be reused in various projects.
Applications include some combination of models, views, templates, template tags, static files, URLs, middleware, etc. They’re generally wired into projects with the INSTALLED_APPS setting and optionally with other mechanisms such as URLconfs, the MIDDLEWARE setting, or template inheritance.
It is important to understand that a Django application is a set of code that interacts with various parts of the framework.

Using Django framework only with admin backend without any apps

I want to use Django only with admin backend without any apps. So actually all I want to do is to use the admin backend to CRUD my database. Now apparently the admin backend does not have a models.py and no views.py.
Do I really need the models.py from an app, or can I easily use only the admin backend to CRUD my database. How would I do this, add a models.py to the admin backend?
First of all, if you want to CRUD something, you will need a model so you can interact with your database (SQLite, Postgres, etc).
However, a model belongs to an app, once this is the core of Django. So, take a look at https://docs.djangoproject.com/en/2.2/topics/db/models/ where you can read more about that.
If you need a tutorial, take a look at https://docs.djangoproject.com/en/2.1/intro/tutorial02/
In summary, yes, you need an app. However, you do not need a view, once there will be no router, I suppose. Just expose your model to the admin, for instance:
from django.contrib import admin
from .models import YourModel
admin.site.register(YourModel)
Hope it helps

How to remove Wagtail Core, Images, Documents from Django Admin

I have a project that uses a Django app and a Wagtail App. In my Django admin (localhost/django-admin/) I get Wagtail panels that I want to hide. How could I do that?
Unregistering Wagtail models from the Django admin are basically the same as unregistering Django models. Had to check where the models are imported from.
Note: Make sure your own apps come after the django and wagtail core apps.
https://books.agiliq.com/projects/django-admin-cookbook/en/latest/remove_default.html
from wagtail.images.models import Image
from wagtail.core.models import Site, Page
from wagtail.documents.models import Document
admin.site.unregister(Document)
admin.site.unregister(Site)
admin.site.unregister(Page)
admin.site.unregister(Image)

Django views accessible in the admin site

I would like to embed front end views in my django admin site at any possible specified locale, maybe in a class or site admin dashboard;anywhere I feel is the best option.. Tried out a few git projects but seems they are not compatible with current django versions..any one offering any idea?!
The Django Admin site is intentionally a separate site, with its own views.
In any app you can make functions that compute various values; but the Admin for that app will need to define its own views, using whatever functions you like.

How to keep Django Flat Pages under version control?

Django flatpages is a very basic CMS
Django-reversions enables a backup of models past versions access in the admin https://github.com/etianen/django-reversion
How can I keep the flatpages app models under reversion? The models are not explicitly set in my code but come as a built in django feature that is autodiscovered by the admin.
You can register third party models like this
from django.contrib.flatpages.models import Flatpage
from reversion.helpers import patch_admin
patch_admin(Flatpage)
See docs