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

improve performance of access form #443 #445

Merged
Merged
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
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
Loading