[Answer]-Check if user has chosen a value from many to many field

1👍

ManyToMany fields are attached to the instance as a special manager, but it respects most of the standard manager API. So for model:

class Person(models.Model):
    cars = models.ManyToMany(Car)

To find out if a person instance has any cars:

# Most pythonic
person.cars.exists()

# or
person.cars.count() == 0

Leave a comment