Django ORM - Model Field Validators / Writing Custom Validators / ModelForms

Sdílet
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

Komentáře • 27

  • @bugbytes3923
    @bugbytes3923  Před 2 měsíci +1

    Playlist link: czcams.com/video/EsBqIZmR2Uc/video.html

  • @amine63404
    @amine63404 Před 4 měsíci +1

    Nothing to say except that this is another great tutorial.
    Thank you very much.

  • @anatoliyloboda4601
    @anatoliyloboda4601 Před 5 měsíci

    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!!!

    • @bugbytes3923
      @bugbytes3923  Před 5 měsíci +1

      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.

    • @anatoliyloboda4601
      @anatoliyloboda4601 Před 5 měsíci

      @@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.

  • @Dorso2009
    @Dorso2009 Před 9 měsíci +1

    Great series so far! Thank you!!

  • @deldridg
    @deldridg Před měsícem +1

    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

    • @bugbytes3923
      @bugbytes3923  Před měsícem

      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.

  • @JustinSpryce
    @JustinSpryce Před rokem

    Great lesson

  • @Ego_Maritm
    @Ego_Maritm Před rokem +1

    Thank you for the great video bro💪

  • @robhafemeister3100
    @robhafemeister3100 Před rokem +1

    Lyle, great stuff as always

  • @nileshswami2426
    @nileshswami2426 Před 7 měsíci +1

    Love you ❤ great work

  • @saptechstuff1497
    @saptechstuff1497 Před rokem +2

    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

    • @bugbytes3923
      @bugbytes3923  Před rokem

      Thanks! Good suggestions too 👍

    • @AliHassan-wc6nb
      @AliHassan-wc6nb Před rokem

      Great work. One request! How to validate debits =credits in diulbe entry system before saving model form.

  • @frameff9073
    @frameff9073 Před rokem +1

    thank

  • @Peterstavrou
    @Peterstavrou Před 10 měsíci +1

    Another great video! How come you never use CBV?

    • @bugbytes3923
      @bugbytes3923  Před 10 měsíci

      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!

  • @SaumyenPDeka
    @SaumyenPDeka Před 11 měsíci

    How to create multiple validators for a single field?

  • @ibrahimoglu
    @ibrahimoglu Před 11 měsíci

    👍