Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[admin] Fix performance issues by using raw_id_fields for the headquarter field #4

Merged
merged 5 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 additions & 19 deletions django_sirene/admin.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
from django.contrib import admin
from .models import Institution
from .models import Activity, Institution, LegalStatus, Municipality


class InstitutionAdmin(admin.ModelAdmin):
search_fields = (
'siret',
"name",
"commercial_name"
)
search_fields = ("siret", "name", "commercial_name")
list_select_related = (
'legal_status',
'headquarter',
'municipality',
'activity',
"legal_status",
"headquarter",
"municipality",
"activity",
)
list_display = (
'siret',
'__str__',
'zipcode',
'municipality',
'headquarter',
'is_headquarter',
'is_expired',
'updated',
'created',
"siret",
"__str__",
"zipcode",
"municipality",
"headquarter",
"is_headquarter",
"is_expired",
"updated",
"created",
)
autocomplete_fields = ("activity", "legal_status", "municipality")
raw_id_fields = ("headquarter",)


admin.site.register(Institution, InstitutionAdmin)


class DjangoSireneBaseAdmin:
search_fields = ("code", "name")


class ActivityAdmin(DjangoSireneBaseAdmin, admin.ModelAdmin):
pass


admin.site.register(Activity, ActivityAdmin)


class LegalStatusAdmin(DjangoSireneBaseAdmin, admin.ModelAdmin):
pass


admin.site.register(LegalStatus, LegalStatusAdmin)


class MunicipalityAdmin(DjangoSireneBaseAdmin, admin.ModelAdmin):
pass


admin.site.register(Municipality, MunicipalityAdmin)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='django-sirene',
version='0.2',
version='3.0.3',
packages=find_packages(),
install_requires=[
"django-bulk-update>=2.2.0",
Expand Down