Answer the question
In order to leave comments, you need to log in
How to add a list of users id to Django-Admin field?
In the system table User, you need to store a list of users. Let's say the field will be CharField, How to make the Django admin panel enter usernames (in the form of tags with usernames), but save, preferably as an id?
It’s easier on the frontend, but here you need to shovel a bunch of docks if you haven’t come across this ...
Even if I figured out how to expand / replace the User table itself.
Answer the question
In order to leave comments, you need to log in
https://github.com/applegrew/django-select2
https://github.com/asyncee/django-easy-select2
If I understood the question correctly, I can offer such a solution.
Add to the overridden user model, for example, MyUser field m2m to the same model:
from django.contrib.auth.models import AbstractUser
from django.db import models
class MyUser(AbstractUser):
...
users = models.ManyToManyField('self', blank=True)
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.utils.translation import ugettext_lazy as _
@admin.register(User)
class MyUserAdmin(AuthUserAdmin):
...
fieldsets = AuthUserAdmin.fieldsets + ((_('Users'), {
'fields': ('users', )
}), )
search_fields = ['first_name', 'last_name']
autocomplete_fields = ['users']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question