Django: How to add users from group view in django admin? - django

How can i add users to a group using django admin just like adding permission ?
A found an answer for older version of django
https://stackoverflow.com/a/39648244/11616789
How can i implement it in django 2 and above

Related

How to I add custom permissions in Django rest framework

I wanted to ask if can we use model-level permissions from Django in Django rest-framework or do we have to create custom permission differently for Django rest-framework?
permission = Permission.objects.get(codename = 'is_seller')
self.request.user.user_permissions.add(permission)
the above code to add permission when a form is submitted is not adding the permission and is showing the error that user_permission does not have an object add()

Generic django admin per client

In my django project, i would like to use Django Admin for multiple organization. So in django urls system, i try to use a system like that :
urlpatterns = [
path('<organization>/admin', admin.site.urls)
]
With that syntax,on a simple example (default startproject+setup), i got an 'NoReverseMatch' :
Reverse for 'logout' with no arguments not found. 1 pattern(s) tried: ['(?P<client>[^/]+)\\/admin\\/logout\\/$']
At the end i try to implement a system like that:
Basic auth user (maybe change backend for email)
Organization:
Organization_User (inherit from basic auth or relationship)
Organization_Area (manyTomany with Organization_User)
and for urls i don't know if syntax bellow works:
www.example.com/admin => admin SuperUser only
www.example.com/organization1/admin => Admin for Organization 1
www.example.com/organization2/admin => Admin for Organization 2
I'm asking myself, is it possible to do that only with Django Admin system ?
For example, use one Admin and try URL filtering or use AdminSite inheritence
Best Regards,
Could you just assign users to groups depending on which organisation they belong to? Then alter the groups permissions so they can only see the parts you wish them to have access to.

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.

Django Admin - Configuring Change List Entries

In Django admin, As of now, change list of a model shows 100 entries per page. Is there any configuration available to customize this limit?
You need a list_per_page attribute in your Django admin.py:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_per_page