mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 17:53:31 +02:00
wip
This commit is contained in:
parent
08dcdb85cd
commit
fc7a3c618d
1 changed files with 8 additions and 2 deletions
|
@ -116,7 +116,8 @@ class RegistrarFormSet(forms.BaseFormSet):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
query = getattr(obj, join).order_by("created_at").all() # order matters
|
query = getattr(obj, join).order_by("created_at").all() # order matters
|
||||||
|
logger.info(obj._meta.get_field(join).related_query_name())
|
||||||
|
related_name = obj._meta.get_field(join).related_query_name()
|
||||||
# the use of `zip` pairs the forms in the formset with the
|
# the use of `zip` pairs the forms in the formset with the
|
||||||
# related objects gotten from the database -- there should always be
|
# related objects gotten from the database -- there should always be
|
||||||
# at least as many forms as database entries: extra forms means new
|
# at least as many forms as database entries: extra forms means new
|
||||||
|
@ -132,6 +133,11 @@ class RegistrarFormSet(forms.BaseFormSet):
|
||||||
# matching database object exists, update it
|
# matching database object exists, update it
|
||||||
if db_obj is not None and cleaned:
|
if db_obj is not None and cleaned:
|
||||||
if should_delete(cleaned):
|
if should_delete(cleaned):
|
||||||
|
if getattr(db_obj, related_name).count() > 1:
|
||||||
|
# Remove the specific relationship without deleting the object
|
||||||
|
getattr(db_obj, related_name).remove(self.application)
|
||||||
|
else:
|
||||||
|
# If there are no other relationships, delete the object
|
||||||
db_obj.delete()
|
db_obj.delete()
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue