[Django]-Django: Direct assignment to the forward side of a many-to-many set is prohibited. Use user.set() instead

8👍

You can add to Many-to-Many relationship by using add
Read the docs: https://docs.djangoproject.com/en/4.0/topics/db/examples/many_to_many/#many-to-many-relationships

def log_concert_and_song(request, concertdict):
if request.method == "POST":
    Concert_save = Concert(
    concertid=concertdict['id'], 
    date=concertdict['eventDate'], 
    venue=concertdict['venue'], 
    city=concertdict['city'], 
    country=concertdict['country'], 
    )
    Concert_save.save()

    Concert_save.user.add(request.user)

or as error says:

list_of_users = [request.user,]
Concert_save.user.set([list_of_users])

Leave a comment