Skip to content

Commit

Permalink
improve performance of access form #443
Browse files Browse the repository at this point in the history
  • Loading branch information
neoflex committed Aug 8, 2023
1 parent 852addd commit 65427c0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/forms/access.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.forms import ModelForm, DateInput, Textarea

from core.models import Access
from core.models import Access, Contact


class AccessForm(ModelForm):
Expand All @@ -24,6 +24,9 @@ def __init__(self, *args, **kwargs):
self.fields["defined_on_locations"].choices = [
(d.id, d) for d in dataset.data_locations.all()
]
# to improve form performance we directly select related contact types
contact_queryset = Contact.objects.all().select_related("type")
self.fields["contact"].queryset = contact_queryset

field_order = [
"contact",
Expand All @@ -39,8 +42,8 @@ def __init__(self, *args, **kwargs):
class AccessEditForm(ModelForm):
class Meta:
model = Access
fields = '__all__'
exclude = ['created_by', 'history']
fields = "__all__"
exclude = ["created_by", "history"]
widgets = {
# Date pickers
"granted_on": DateInput(attrs={"class": "datepicker"}),
Expand Down

0 comments on commit 65427c0

Please sign in to comment.