I have a video model that stores ‘likes’ as a manytomany field with User.
e.g
class Video(models.Model):
...
likes = models.ManyToManyField(User)
....
When I create a ModelForm based on Video Likes is displayed as a dropdown with a list of all users. This is obviously ont what I want. I would like a particular user to be able to add/ remove their own name from this list. How do I instead display ‘likes’ as a checkbox and still have the form validate correctly?
In your model form, create a custom field for likes; when this field is checked, set
likestorequest.user.This will render likes as a checkbox (the default widget for BooleanField).