Python Django Module Connection promblem - django

What will i do when 3 modules in Python Django,they are User ,admin,super admin when super admin has power to do CRUD and User only View the product
What will i do when 3 modules in Python Django,they are User ,admin,super admin when super admin has power to do CRUD and User only View the product

Related

How to connect inbuilt User database to another one in Django?

I am a beginner in Django. I have created a login, logout and register pages for my Django projects. When a user signs in I want them to only the posts that they have made. I am not sure how to make the users that I already have be able to login into their own pages and manage their budgets and etc.
Image of code
from django.db import models
from django.contrib.auth.models import User# user authentication
from django.contrib.auth import get_user_model#for connecting the inbuild user database
class List(models.Model):
user = models.ForeignKey(User)
item = models.CharField(max_length=200)#field to type the name of the budget
completed = models.BooleanField(default=False)#this needs to be changed later
def __str__(self):
return self.item + ' | ' + str(self.completed)
Django contrib auth is a good way to handle basic user system https://docs.djangoproject.com/en/3.1/ref/contrib/auth/. Then you can use request.user when a user is logged in, filter a queryset in your view and and show them just their posts or lists List.objects.filter(user=request.user)

wrong url to admin django after adding profile

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

how to use logging django admin all log to file

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

Saving user's social auth name using python social auth in django

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.

How to allow non staff upload pictures with Django-TinyMCE and FileBrowser?

I'm using
* Django 1.3
* Django-TinyMCE 1.5 trunk
* Filebrowser 3.4
Now if I login with an account which is_staff, I could upload pictures via TinyMCE's insert image button. While if it is not a staff, the pop up window will redirect to django admin login page and if I login with is_staff account, the pictures will be listed.
How could I allow non staff to upload picture?
Override the clean method in the AdminAuthenticationForm class
Create a view outside the admin where a user can upload
Make the user staff
You do realize that if you do point 1 or 3 the user will have access to the whole admin section? That is probably not what you want so you should go with point 2.