Skip to content

Commit

Permalink
Add replace_existing_version field on the AddToProduct form #12
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed May 24, 2024
1 parent 68964a6 commit 5ba377f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions component_catalog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ class AddToProductAdminForm(forms.Form):
queryset=Product.objects.none(),
)
ids = forms.CharField(widget=forms.widgets.HiddenInput)
replace_existing_version = forms.BooleanField(
required=False,
initial=False,
label="Replace existing relationships by newer version."
)

def __init__(self, request, model, relation_model, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -663,9 +668,12 @@ def get_selected_objects(self):

def save(self):
product = self.cleaned_data["product"]
replace_existing_version = self.cleaned_data["replace_existing_version"]

return product.assign_objects(
related_objects=self.get_selected_objects(),
user=self.request.user,
replace_existing_version=replace_existing_version,
)


Expand Down

0 comments on commit 5ba377f

Please sign in to comment.