Django ORM - Model Field Validators / Writing Custom Validators / ModelForms
Vložit
- čas přidán 28. 06. 2024
- In this video, we'll look at Django model field validators, such as the MinValueValidator, MaxValueValidator, as well as writing our own custom validator functions.
We'll also briefly look at how ModelForms hook into models, and use the validators that are defined on fields on the model that are included in the ModelForm.
Finally, we'll see how ModelForm subclasses pull choices that are defined on a model field into the form as options in a select field.
To see more on using Validators, you can also check this video where we validate the FILE EXTENSION of an uploaded file using Django's FileExtensionValidator:
• Django Media Files - R...
📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
01:56 Using Django MinValueValidator & MaxValueValidator
06:09 Creating a ModelForm that uses model field validators
13:21 Writing custom validator functions
17:17 Using Choices in Django forms
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
ko-fi.com/bugbytes
▶️ Full Playlist:
• Django ORM Deep Dive
𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: bugbytes.io/posts/
👾 Github: github.com/bugbytes-io/
🐦 Twitter: / bugbytesio
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Django Validators: docs.djangoproject.com/en/4.2...
ModelForms: docs.djangoproject.com/en/4.2...
#python #django #webdevelopment #database #sql
Playlist link: czcams.com/video/EsBqIZmR2Uc/video.html
Nothing to say except that this is another great tutorial.
Thank you very much.
Thanks so much!
As an amateur I face with a lot of issues with Django but looking these amazing lessons I become more aware of the main ideas. Thanks for your contributions in my education!!!
Thanks a lot for the comment, that is really great to hear - best of luck with your Django journey! If you have any suggestions for videos that may help, feel free to drop them here.
@@bugbytes3923 I haven't finished your django jorney therefore I do not know whether the answers on my qustions are available or not.
I face filtering user application by various attributes ascwell as giving some parameters depending on the chosen.
For example, when I choose a brand I want to iterate in filters only for those models that belong to that particular brand.
Great series so far! Thank you!!
Thanks a lot!
Succint and clear. You are an excellent presenter and this has helped fast track my Django learning. Much appreciated mate from a new Aussie subscriber in Sydney - Dave
PS. Noting that validation can be done in the form class and at the model level, is there a rule of thumb for choosing the most appropriate approach? My guess is to keep validation as close to the db as possible. Cheers - D
Thanks a lot, really appreciate the support Dave! Greetings from Glasgow, Scotland!
Agreed, setting up validation at the DB level is most important for data integrity. Form-level validations are important too - can prevent you hitting the database unnecessarily if there's any issues with the submitted data.
Great lesson
Thank you for the great video bro💪
No problem - thank you for watching!
Lyle, great stuff as always
Thanks as ever, Rob!
Love you ❤ great work
Thanks a lot!
thanks, very useful topic, it would be very helpful if you post a video on displaying table data in django and other topics that would be useful are how to deploy the django web app on a live web server and interactive charts based on multiple inputs on the web page and finally a how to video on clean and fully designed UI with interactive input boxes and dropdowns
Thanks! Good suggestions too 👍
Great work. One request! How to validate debits =credits in diulbe entry system before saving model form.
thank
You're welcome, thanks for watching!
Another great video! How come you never use CBV?
Thank you! I have a preference for functions for learning and for the videos, tbh - I believe they're more explicit in a lot of cases. But sometimes it depends on the project, the other developers, etc. With DRF I'd use CBVs always.
I do like CBVs too!
How to create multiple validators for a single field?
👍
Thanks!