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
Related
I have added Google authentication for my Django web application using allauth package. I want to access the extra data(shown in field 4(Extra data) of social account users
I have tried this but, I do not import SocialAccount(I dont know to which module does it belongs to).
data=SocialAccount.objects.get(user=request.user).extra_data
Please let me know which module should I import to use SocialAccount or tell me other way how can I access extra data.
Use it like this:
from allauth.socialaccount.models import SocialAccount
Now, use the SocialAccount model like any other Django model
SocialAccount.objects.all()
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.
I am learning Django, I saw so many videos of DJango.
I just wanted to know one thing that can we create an app (like login app, or contact app) without registering it into in admin (admin.py).
Off course it should have model etc to save the contact details or login details etc. Is it possible in Django ?
Just don't create your admin.py file or not register the model that you don't want to see there. Django admin is fully optional.
I need some good way to provide admin users of my django 1.5 app, manage some various app parameters, these parameters or settings are different from the app core settings, ... can anyone point some directions for this ??
thanks everyone
You can create an app and use a Model to handle all the possible parameters that you need to use. Then register your admin for this app, and you will be able to change an use this values.
I always have a utils app, that I can put some code that can be shared within the project and along all the projects that I work, so I can give you a suggestion to put this in your utils app:
#models.py
from django.db import models
class Parameters(models.Model):
default_product_price = models.IntegerField(default=10) # you can change this in admin
...
Then, register your classes in admin.py
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