[Answered ]-The problem with adding data to Many To Many Django

1👍

You must create a Station instance first and then add the many to many fields inside the instance.

stations_arr = []
for additional_id in additional_ids:
    ....
    services = Services.objects.filter(id=1)
    additional = Additional.objects.filter(id__in=[additional_id])
    stations = Stations.objects.get(id=id)
    stations.service.add(services)
    stations.additional.add(additional)
    station.save()

I haven’t tried this in your code but this should get you started on your solution.

👤Anjaan

Leave a comment