Skip to content

Commit

Permalink
chore: fix passing unsaved objects to related filters
Browse files Browse the repository at this point in the history
  • Loading branch information
afuetterer committed Sep 11, 2023
1 parent 2b47a5b commit c2685ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions rdmo/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, *args, **kwargs):
self.fields['last_name'].widget = forms.TextInput(attrs={'placeholder': _('Last name')})

self.additional_fields = AdditionalField.objects.all()
self.additional_values = self.instance.additional_values.all()

# add fields and init values for the Profile model
for additional_field in self.additional_fields:
Expand All @@ -46,8 +45,10 @@ def __init__(self, *args, **kwargs):

self.fields[additional_field.key] = field

for additional_field_value in self.additional_values:
self.fields[additional_field.key].initial = additional_field_value.value
# existing user is going to be updated
if self.instance.pk is not None:
for additional_field_value in AdditionalFieldValue.objects.filter(user=self.instance):
self.fields[additional_field.key].initial = additional_field_value.value

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Expand Down
11 changes: 8 additions & 3 deletions rdmo/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,15 @@ def __init__(self, *args, **kwargs):

# add fields for the integration options
for field in self.provider.fields:
try:
initial = IntegrationOption.objects.get(integration=self.instance, key=field.get('key')).value
except IntegrationOption.DoesNotExist:
# new integration instance is going to be created
if self.instance.pk is None:
initial = None
# existing integration is going to be updated
else:
try:
initial = IntegrationOption.objects.get(integration=self.instance, key=field.get('key')).value
except IntegrationOption.DoesNotExist:
initial = None

if field.get('placeholder'):
attrs = {'placeholder': field.get('placeholder')}
Expand Down

0 comments on commit c2685ae

Please sign in to comment.