[Django]-How do I make many-to-many field optional in Django?

508👍

If you want to be able to specify ManyToMany relation without making it required just use blank=True:

class Group(models.Model):
    ...
    events = models.ManyToManyField(Event, blank=True)

3👍

If Ludwik’s answer does not solve the issue, set required to false in the serializer as well:

class RecipeDetailSerializer(RecipeSerializer):
    """Recipe detail serializer"""
    tags = TagSerializer(many=True, required=False)

Leave a comment