Skip to content
Snippets Groups Projects

Resolve "update of appointment clears data from daily planning"

1 file
+ 12
3
Compare changes
  • Side-by-side
  • Inline
+ 12
3
@@ -241,11 +241,20 @@ class AppointmentEditForm(ModelForm):
def save(self, commit=True):
appointment = super(AppointmentEditForm, self).save(commit)
AppointmentTypeLink.objects.filter(appointment=appointment).delete()
appointment_type_links = AppointmentTypeLink.objects.filter(appointment=appointment).all()
appointment_types_from_links = []
appointment_types = self.cleaned_data['appointment_types']
for appointment_type_link in appointment_type_links:
if appointment_type_link.appointment_type not in appointment_types:
# we delete appointment links for appointments types that have been removed
appointment_type_link.delete()
else:
appointment_types_from_links.append(appointment_type_link.appointment_type)
for appointment_type in appointment_types:
appointment_type_link = AppointmentTypeLink(appointment=appointment, appointment_type=appointment_type)
appointment_type_link.save()
if appointment_type not in appointment_types_from_links:
# we create new appointment links for appointements types that have been added
appointment_type_link = AppointmentTypeLink(appointment=appointment, appointment_type=appointment_type)
appointment_type_link.save()
return appointment
Loading