Django admin distribution of 1000 users

Hypothetically: I have a model called Car that applies to a single user. My problem is with the default Django admin. I assign the user to the machine via the drop-down menu (this is the default Django behavior, so they tell me).

What happens when I have 1000 + users who can be selected from the drop-down list. The administrator copes with this, if so, how?

+5
source share
3 answers

The administrator will still display the default selection window, but you need to use the prominent id id instead using the option raw_id_fields: https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin .ModelAdmin.raw_id_fields

By default, the Djangos administrator uses the select-box () interface for the ForeignKey field. Sometimes you do not want the overhead associated with the need to select all relevant instances to display in the drop-down list.

+6
source

You can see django-grappelliwhich is an application that improves the admin interface. The documentation describes autocomplete relationships ForeignKeyor ManyToManyusing raw_id_fields.

+4
source

django-select2 https://github.com/applegrew/django-select2.

- :

from django_select2 import AutoModelSelect2Field

class CategoryChoices(AutoModelSelect2Field):
    queryset = models.Category.objects
    search_fields = ['name__icontains', 'code__icontains']

class NewsAdminForm(forms.ModelForm):
    category = CategoryChoices()

    class Meta:
        model = models.News
        exclude = ()

# register in admin
class NewsAdmin(admin.ModelAdmin):
    form = NewsAdminForm
admin.site.register(News, NewsAdmin)
+3

All Articles