I have deployed a innner django web site , i have register some model class in admin.py like:
admin.site.register(models.Receiving)
admin.site.register(models.Vendor)
admin.site.register(models.Creator)
admin.site.register(models.CategoryOfitem)
i want to let all user operate all action at admin log write into a file ,how i can use the logging do it?
Log is in django_admin_log table in database used by django
Logging activity on Django's admin - Django
Related
I wanted to customize my django admin route
Not from /admin to something else but to add new clickable custom route inside admin panel
Currently I have created superuser using python manage.py createsuperuser command.
I can login to django admin panel , but what I want is to have a custom route to be displayed in left sidebar or anywhere else after logging into django admin panel. My custom route is like localhost:8000/my-view/ and my-view should be displayed somewhere in admin panel.
TIA.
I want to show data from DynamoDB on the Django admin panel page. I have tried PynamoDB to create the model and register it with the admin panel.
I am facing the following two issues:
Getting only attribute 'id' instead of all attributes from the DynamoDB table. I have confirmed this issue while fetching attribute_definitions from the DynamoDB table using boto3.
attribute_definitions = table_name.attribute_definitions
The second issue I am facing is that I get errors while registering the created Model(by using PynamoDB) with the admin panel. I get the issue
"TypeError: 'MetaModel' object is not iterable"
you can pass this data to admin template using this method
changelist_view
Ex:
class DynmoDbAdmin(admin.ModelAdmin):
def changelist_view(self, request, extra_context=None):
get data from dynamodb
add this data to extra_context
return super().changelist_view(request, extra_context=extra_context)
after that
you need to extend admin template
follow this pattern
add 'APP_DIRS': True, to your settings file.
go to your app and create this folders templates/admin/model_name
in this folder create file change_list.html
this links will help you.
https://docs.djangoproject.com/en/3.2/howto/overriding-templates/
How to override and extend basic Django admin templates?
If I have a PostgresDB that contains both Django models and other SQL tables, is it possible to register these other SQL tables in the Django admin panel?
More details about the setup:
I have a docker-compose setup where Django is running in one container, a Postgres DB in another, and a slack-app in a third container. Django is connected to the DB and the models are registered in the admin panel. This works as intended. The slack-app is also connected to the same DB and has some tables there that are not Django-models. I would like to also access these through the Django admin panel in order to have everything in one place. Is this possible?
You can define unmanaged models in Django. These models will not construct migrations, but will only query the database to select, insert, etc.
Django offers a tool inspectdb [Django-doc] to inspect the database and write the corresponding unamanged models. You thus can use this with:
python3 manage.py inspectdb table1 table2 tablen
It will then write the corresponding models for these tables to the standard output channel, and you thus can copy these in the models.py. In the Meta of these models it will add a managed = False to denote that Django will not migrate these models.
Once you registered these models, you can register a ModelAdmin with:
from django.contrib import admin
from app_name.models import Model1, Model2, Modeln
admin.site.register(Model1)
admin.site.register(Model2)
admin.site.register(Modeln)
I had a login page that I would change it to another login page and I follow these instructions.
I added this code and when I tried to login to my user admin that I added before it sends me to wrong url http://localhost:8050/admin/login/?next=/admin/ and it throws :
RelatedObjectDoesNotExist at /admin/login/
User has no profile
The profile instance is generated on post_save signal, that is, you must save your User at least once after you added that Profile class.
The easiest workaround in your case would be to create a new admin user using python manage.py createsuperuser.
The error seems like, You have a User in DB, but it doesn't have any profile relation now.
Solution:1
Set profile instance for currently existing User's in db through django shell.
1. log into django shell by python manage.py shell
2. run these commands,
from django.contrib.auth.models import User
from myapp.models import Profile
for user in User.objects.all():
Profile.objects.create(user=user)
3. then login to the django admin
Solution:2
Drop your database, (if you are using sqlite, the delete the corresponding file) and migrate and then create a new super user by python manage.py createsuperuser command
I work on django project that migrate from django social auth to python social auth.
Previously new social auth user first name/last name will be saved automatically for first time login.
Now after using python social auth, it's not.
Seems I have to use this setting:
SOCIAL_AUTH_USER_MODEL
but
SOCIAL_AUTH_USER_MODEL = 'django.contrib.auth.models.User'
generate error when invoking runserver:
django.core.management.base.CommandError: One or more models did not validate:
default.usersocialauth: 'user' has a relation with model web.models.User, which has either not been installed or is abstract.
Wanted to try subclassing User model in the project
from django.contrib.auth.models import User
class User(User):
but that is not feasible right now.
Also saving manually the name from response data in custom pipeline is prohibited as well.
Really want to know if there any other solution?
Thanks.
remove SOCIAL_AUTH_USER_MODEL because you are using Django Default User model.