In this video, we look at the ModelChoiceField in Django Forms, that allows a form to link to Foreign Key objects in a select element. We will see how to style the form with django-crispy-forms and Bootstrap 5, and also how to add a Select2 widget to the select element, allowing users to search through the list of Foreign Key objects. After looking at foreign key relations, we'll also see how to add multiple related objects in a form to a model's ManyToManyField, using the ModelMultipleChoiceField in Django. Finally, we will also see how to customize the QuerySet passed to the ModelChoiceField and ModelMultipleChoiceField - allowing the related items in the select element to be filtered. ๐ ๐๐ต๐ฎ๐ฝ๐๐ฒ๐ฟ๐: 00:00 Intro 02:11 Creating Django Form with a ModelChoiceField 08:00 Handling POST request in Django view 11:39 Styling form with django-crispy-forms 13:46 Adding select2 to ModelChoiceField for searchable dropdown 16:14 Limiting foreign-key queryset in ModelChoiceField 17:48 Adding multiple relations with ModelMultipleChoiceField 20:46 Database junction table for ManyToManyField โ๏ธ ๐๐๐ ๐บ๐ฒ ๐ฎ ๐ฐ๐ผ๐ณ๐ณ๐ฒ๐ฒ: To support the channel and encourage new videos, please consider buying me a coffee here: https://ko-fi.com/bugbytes โถ๏ธ Full Playlist: ๐ฆ๐ผ๐ฐ๐ถ๐ฎ๐น ๐ ๐ฒ๐ฑ๐ถ๐ฎ: ๐ Blog: https://bugbytes.io/posts/ ๐พ Github: https://github.com/bugbytes-io/ ๐ฆ Twitter: https://twitter.com/bugbytesio ๐ ๐๐๐ฟ๐๐ต๐ฒ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐ถ๐ป๐ณ๐ผ๐ฟ๐บ๐ฎ๐๐ถ๐ผ๐ป: Github: https://github.com/bugbytes-io/django-modelchoicefield-demo ModelChoiceField: https://docs.djangoproject.com/en/4.2/ref/forms/fields/#modelchoicefield ModelMultipleChoiceField: https://docs.djangoproject.com/en/4.2/ref/forms/fields/#modelmultiplechoicefield Django-crispy-forms: https://django-crispy-forms.readthedocs.io/en/latest/ Crispy-bootstrap5: https://pypi.org/project/crispy-bootstrap5/ jQuery: https://releases.jquery.com/ Select2: https://select2.org/getting-started/installation#using-select2-from-a-cdn UserCreationForm: https://docs.djangoproject.com/en/4.2/topics/auth/default/#django.contrib.auth.forms.UserCreationForm #python #django #webdevelopment