Это видео недоступно.
Сожалеем об этом.

How To Add Calculated Fields To Models - Django Wednesdays #40

Поделиться
HTML-код
  • Опубликовано: 14 авг 2024
  • In this video I'll show you how to add a calculated field to your models with Django and Python.
    Adding calculated fields allows you to make calculations using the data in your model, without actually adding extra fields to your model.
    This lets you do things on the fly in real time that you might not be able to easily do with just the model itself.
    We'll be using @property for this.
    #django #codemy #JohnElder
    Timecodes
    0:00​​ - Introduction
    1:18 - Create @property in models.py
    3:00 - Change Date on an Event
    3:25 - Change Order of Events
    3:50 - Add Days_till To HTML Template
    4:50 - Import Datetime Date
    5:03 - Get Event Date From Model
    6:08 - Get Today's Date
    6:17 - Compare Today's Date To Event Date
    6:51 - Strip Out Time From Date Till
    8:18 - Find If Event Is Past or Future
    9:31 - Conclusion

Комментарии • 47

  • @Codemycom
    @Codemycom  2 года назад

    ▶️ Watch Entire Django Wednesdays Playlist ✅ Subscribe To My RUclips Channel:
    bit.ly/35Xo9jD bit.ly/2IGzvOR
    ▶️ See More At: ✅ Join My Facebook Group:
    Codemy.com bit.ly/2GFmOBz
    ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
    Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
    ▶️ Get The Code
    bit.ly/3sJpeV6

  • @clivethompson5016
    @clivethompson5016 2 года назад +5

    fantastic video as always!
    This channel should be the biggest coding channel on youtube!
    edit: typo

  • @collen89c5
    @collen89c5 Год назад +1

    Thanks my man you realy saved the day , great video
    Assist pliz -- how do i compare todays current time and event time

  • @brunomandela3480
    @brunomandela3480 11 месяцев назад

    yo man you have no idea how this has helped out even that second @properties you did ,esspecially that one, fixed a lot of problems for me. Keep making more great content and stay blessed brother.

    • @Codemycom
      @Codemycom  11 месяцев назад +1

      Happy to hear it!

  • @kumara2mahe
    @kumara2mahe 2 года назад

    This video really saves my day, and all your videos are awesome.

  • @madesastra4145
    @madesastra4145 2 года назад

    Great video. So simple and straightforward👍

  • @charlesenglebert8226
    @charlesenglebert8226 Год назад +1

    hello
    How to make computed field available in admin ?

  • @joachimkre5682
    @joachimkre5682 2 года назад +1

    Un bon exposé. Mes félicitations pour tout ce que vous faites. Je voudrais rappeler que la différence entre 2 dates en Python ne fait pas apparaitre "days 00:00:00" quand les deux dates sont égales. Par conséquent, le split() donnera une erreur. Merci

  • @1412-kaito
    @1412-kaito Год назад

    Okay, so what would the steps be if i want to store some calculated info. in the forms and make i non-editable for non-admins?

  • @MrElectrecity
    @MrElectrecity 2 года назад

    Quick tip 😁
    You can use date template tag to print only the date
    Thanks for your works sharing
    💖💖💖💖

  • @pouoiza6875
    @pouoiza6875 2 года назад

    Thank you so much sir.😷

  • @TheGodfather360
    @TheGodfather360 2 года назад

    Hi, I have two models and the names are Budget and Transaction. One budget can have multiple transactions, I would like to sum each transaction and subtract the total from the particular budget. I used the @property decorator, but how include this calculation from different models. Thanks in advance!

  • @nadirnacef2223
    @nadirnacef2223 2 года назад +1

    I like this guy he looks like Walter white from the breaking bad serie

  • @pouoiza6875
    @pouoiza6875 2 года назад

    Thank you so must Sir

  • @Adrian-mh8op
    @Adrian-mh8op 2 года назад

    I have a few questions. I’m making a flashcard project, I followed your tutorial for the language one but to take it further I want to use SQLite to store the words. I’ve already created my table how do I call the contents for it to be displayed on the GUI of the flashcard.
    Also I have a menu but when I click between the menu the contents of it gradually go further and further down. How do I make it stay stationary when I switch between the menu items

    • @Codemycom
      @Codemycom  2 года назад

      Are you talking about tkinter? I have videos on all that stuff.

  • @yasayah7289
    @yasayah7289 2 года назад

    Merveilleux merci! Would be nice to add email notifications via dropdown email list as an event approaches a certain number of days. Additionally a dashboard with total number of events as well as breakdown number of events of event type...j'apprécie ton tuto merci :)

  • @MatthewCoxPublicProfile
    @MatthewCoxPublicProfile Год назад

    Hey John- perhaps I haven't dived deep enough, but do you have a video on paginating the returned searches?

    • @Codemycom
      @Codemycom  Год назад

      I have a video on pagination

  • @mohammedhassan-kx2yf
    @mohammedhassan-kx2yf 2 года назад

    I need help
    I have a django db model which has a manytomany field.
    Problem i have is adding values to that field from my views.py
    I used obj.field.add(“”)
    Obj.field.set(“)
    Nothing is working

    • @Codemycom
      @Codemycom  2 года назад

      I have many videos about adding things to the database.

    • @clivethompson5016
      @clivethompson5016 2 года назад

      I think it should be obj.feild.addWidget(")

  • @Adrian-mh8op
    @Adrian-mh8op 2 года назад

    Whenever I click my menu item, my label along with what’s on the GUI gradually keep going down with every click of it. How do you fix that, if you could link the video to that, it would be great.
    You’re amazing btw, I learn from your videos all the time

    • @Codemycom
      @Codemycom  2 года назад

      Sorry, I have no idea what you're talking about. This is a django video, there are no menu items or gui's

  • @frozeneye100
    @frozeneye100 Год назад

    pretty cool, except doing exactly that, no access to the property... No idea what causes that issue.

    • @Codemycom
      @Codemycom  Год назад

      what did you do differently?

    • @frozeneye100
      @frozeneye100 Год назад +1

      @@Codemycom I found the issue. I was trying to call the property which returned an object. For testing I placed it in a for loop which did not create any instances of the class. So since there was no instance of the class, of course the object was just an object without an instance for the way in which it was called. Moving it to a loop which did create a class instance worked. So I need to learn a bit more about that and OOP and django.

  • @mohammadrajha5181
    @mohammadrajha5181 2 года назад

    can i get money from my website? if i do a good web

    • @Codemycom
      @Codemycom  2 года назад

      Sure, it depends on the website and it's purpose

  • @kmdown
    @kmdown 2 года назад

    Please Make a video on how to host django site free to show our friends...

    • @clivethompson5016
      @clivethompson5016 2 года назад

      ruclips.net/video/Li0Abz-KT78/видео.html
      it works the same with Django, I think

    • @kmdown
      @kmdown 2 года назад

      Ohh, Thanks a lot

    • @Codemycom
      @Codemycom  2 года назад

      Yeah I have those already on the channel.

  • @mohammadrajha5181
    @mohammadrajha5181 2 года назад

    i wanna free domain pls how

    • @Codemycom
      @Codemycom  2 года назад

      No, domains cost money from a registrar.

  • @Kennerdoll
    @Kennerdoll 2 года назад

    Hello John, is it a good practice to just add:
    if self.event_date.date() > today:
    return days_till_split
    else:
    return "Event passed!
    at 8:18?

    • @Codemycom
      @Codemycom  2 года назад +1

      It's a good practice to do anything you want to do :-p