ValueError: "needs to have a value for field "id" before this many-to-many relationship can be used"

You just need to edit your save method in your form,

def save(self, *args, **kwargs): 
    if not commit: 
        raise NotImplementedError("Can't create User and Userextended without database save") 
    user = super().save(*args, **kwargs)
    user_profile = Userextended(user=user, cristin=self.cleaned_data['cristin']) 
    user_profile.save() 
    user_profile.rolle.add(self.cleaned_data['rolle'])
    user_profile.save()
    return user

You need to save your UserExtended model first, then add the Rolle instances to the many to many relation.

Tags:

Python

Django