Database Model Queries | Django (3.0) Crash Course Tutorials (pt 7)
ฝัง
- เผยแพร่เมื่อ 15 ก.ค. 2024
- Checkout my new Django Course!
dennisivy.teachable.com/p/dja...
Django database queryesets
Follow me on Twitter: / dennisivy11
Linkedin: / dennis-ivanov
Source code + Live Demo: dennis-sourcecode.herokuapp.c...
Holy shit dude this might be the best tutorial series on any subject ever I have seen on TH-cam (not just programming or web development)
Haha thanks Jake :)
I've done 2 Udemy Django classes and 2 youtube tutorial series and this is by far the best of them. The way you take your time to make the slides and layout the queries function and example shows that you care about us. thanks.
Could you recommend a follow up course/site for us beginners after this crash course? Ty
Dennis I cannot stress how helpful and clear your work is. Other channels don’t explain properly or complicate it too much when the point is to introduce simple topics. Im sure you are going a long way ;) Wish you all the best mate!
Best django series on youtube. Learning a lot!! Thanks Dennis!!
Dennis, I can't thank you enough! This "query_set" part was killing me! Even the Django documentation does not cover this topic properly!
Thanks for your precious service to humanity. I nearly quit Django and I chanced on your videos on youtube. You have inspired new hope in me, and have increased my passion for Django. I am amazed by your selfless nature, and your willingness to share knowledge and help others.
So far so good. This tutorial is really detailed, organized and understandable. If you make all of your tutorials like this eventually people gonna discover this channel. You can be the next "code with mosh".
I think this is best ever Django course in TH-cam. You explain things simply! Thank for this course.
this is one of the best tutorials out here on Django, I really understood the database queries more than any pdf or youtube videos. Thanks a lot Sir
Thank you Dennis. This Django series is by far the best series on the internet. Learning a lot from it. Learnt Python from CodeWithHarry, and learning Django from you. I can't thank you enough for this awesome tutorial. Love from Nepal Brother.
One of the smoothest tutorial set I've ever seen.. Thank you!
This is a great series, so easy to follow and descriptive. Keeps me motivated!
Very good your explanations, congratulations for the content and the prepared material.
Excellent quality!
Thank you Luiz:)
This course is the best ... I am learning so much doing this course. Thanks a ton Dennis.
Thank you sir clear all concept of Django.
Thanks Dennis, I really appreciate this series you created.
Ohh man i finally found a good django course...Really love the effort you put into theses videos man...Amazing
This tutorials is far better than many paid. to the point, precise theory concept before implementation
Hey Dennis, this goes to you... You have taught in the best way possible... KUDOS!!! 👌🙏
From 11.01-11.11 instead of using multiple newline you can use ctrl+l that can throw all your terminal codes to above unseen area. Thank you.
you are incredible! You deserve a nice cold beer! Thanks so much, helped me a lot
I'm not gonna lie. This channel is awesome. Got udemy courses and some youtube playlist. But this MAN really THE BEST OF IT. Thanks sir. SAVE ME ON MY SCHOOL PROJECT
I love how you teach. If it wasn't for you I'd probably wouldn't have followed my programing learning. Sincerly, thanks
Wow that inspires me! Thank you for taking the time to comment :) Best of luck
Hope you never stop, great job! Think about document DB or Firebase
Im blown away by how much support I get over this series, thank you! I’m taking this comment into consideration for my next videos :)
K Ken I totally agree with you, I am a beginner and I find it very useful. Thank you Dennis
Thanks so much Denis. Can't believe that your tutorials are free. Better than Python Django Bootcamp that I bought on Udemy which is never updated. Usually I don't subscribe to TH-cam but has to do it on yours because of how good it is. Keep it up.
Thank you :)
Cheat sheet .... Welcome !
#***(1)Returns all customers from customer table
customers = Customer.objects.all()
#(2)Returns first customer in table
firstCustomer = Customer.objects.first()
#(3)Returns last customer in table
lastCustomer = Customer.objects.last()
#(4)Returns single customer by name
customerByName = Customer.objects.get(name='Peter Piper')
#***(5)Returns single customer by name
customerById = Customer.objects.get(id=4)
#***(6)Returns all orders related to customer (firstCustomer variable set above)
firstCustomer.order_set.all()
#(7)***Returns orders customer name: (Query parent model values)
order = Order.objects.first()
parentName = order.customer.name
#(8)***Returns products from products table with value of "Out Door" in category attribute
products = Product.objects.filter(category="Out Door")
#(9)***Order/Sort Objects by id
leastToGreatest = Product.objects.all().order_by('id')
greatestToLeast = Product.objects.all().order_by('-id')
#(10) Returns all products with tag of "Sports": (Query Many to Many Fields)
productsFiltered = Product.objects.filter(tags__name="Sports")
'''
(11)Bonus
Q: If the customer has more than 1 ball, how would you reflect it in the database?
A: Because there are many different products and this value changes constantly you would most
likly not want to store the value in the database but rather just make this a function we can run
each time we load the customers profile
'''
#Returns the total count for number of time a "Ball" was ordered by the first customer
ballOrders = firstCustomer.order_set.filter(product__name="Ball").count()
#Returns total count for each product orderd
allOrders = {}
for order in firstCustomer.order_set.all():
if order.product.name in allOrders:
allOrders[order.product.name] += 1
else:
allOrders[order.product.name] = 1
#Returns: allOrders: {'Ball': 2, 'BBQ Grill': 1}
#RELATED SET EXAMPLE
class ParentModel(models.Model):
name = models.CharField(max_length=200, null=True)
class ChildModel(models.Model):
parent = models.ForeignKey(Customer)
name = models.CharField(max_length=200, null=True)
parent = ParentModel.objects.first()
#Returns all child models related to parent
parent.childmodel_set.all()
thank you and i wish you the best
You know there are turns in life whereafter everything becomes smooth. Your vedios are like dat turn awesome dude..
Hi Dennis, thanks a lot for your effort and you're really a good instructor, good luck
Man the way you teach is awesome.
WAOUH !!!!
VERY COMPLETE PLAYLIST for Beginner
Thank you for these videos. I love this content so much!
I wanna thank you for your efforts and for the amazing videos you make with a very good explanation
good luck
Well done. Nice series.
thank you so much for your work , the way u explain is amazing keep it up :)
659 likes over against 1 dislike describe how gracefully you explained everything...
Thank you so much!
(Great little cheat sheet, too. Saved!)
guess what? today you made me realize that it is the teacher who makes an student interested in learning. believe me constantly I am watching and learning ur tuts and did not get bore yet. truly love you man.
before you I have watched others too but fortunately ended up to urs tuts.
bro this video is really cool and intrustinng thanks and i really appreciated for this type of presentation on Django,
Definitely the best series on django @YT
Super helpful!
Thanks so much!
Thanks a lot ! Amazing work !
You are doing so gooood! I hope you will be famous one day..just keep on working like that ❤👌👍
Haha I appreciate that :)
The way you structured this tutorial on django alongside the source code is amazing... Please do a tutorial on how you hosted it onto heroku... Thanks
Putting this app on heroku soon, hopfully this week :)
your tutorial is awesome and really appreciate the way you explain... thank you.... right now i am going to subscribe and hit that bell icon
Your videos are awesome easy to understand
Sir your Videos are just Awesome thanks a lot..Love from India.
amazing course)
You're Awesome Bro!!!
Bro you doing well. Keep doing for us
thanks Mr dennis
Awesome Thanks a lot!!!!
Hi Dennis. Your video is awesome. It is really nice and understandable. Keep going. And I think you are the best Django teacher because on Russian youtube or American I don't see normal videos. You the best #DennisIvyTheBest #2020
Thank you so much!
Its a very nice and useful video i like it must
best explained thankyou
Hi Dennis Ivy .I am following your tutorials i really like the way you are explaining the things . can you please suggest other projects so i can work as a beginner to explore more about django. Thanks
Hi guys, hi Dennis. Thank you very much for your effort in creating this course.
I have a question related to the ball case in the last part of the video, wouldn't it be easier to add a quantity field to the order table for each chosen item?
Buenísimo gracias
Hey Denise, thank you for this tutorial, really helpful. Could you show how to create a customized id field in a model?
I'd have to do some research on that myself. Haven't really customized any fields outside of adding some widgets. I'm make a video on this once i do some more research :)
@@DennisIvy Sure. Meanwhile ,I've worked on a code myself, where I call a function from a field to add data and set the field to uneditable
Excellent course
12/07/2020
Your series are just awesome, man! I do my best to support you with likes, subscruption, recommendations etc.
damn man, you are the best!
Please Dennis make a series of Html Css and Bootstrap , please !!!! , and by the way you create awesome stuff !!
hey dennis bro please show how to pull the data from many to many datas from table
Dennis thanks a lot for this tutorial. My question is the queriesDemos.py file, do we have to create one for whatever app we are building before we can actually query our database in our templates?
No need, Dennis is just showing examples.
Hi Dennis thank you for your youtube tutorials I know it has been a long time since you posted this one, but I got to ask the source code is not working is there any way we can get them again
thank you keep up the great work
Great
Hello Sir can you help me in this...?
I have two models A and B which having many to many relation and form third model E with extra attributes .
so i want to perform following sql query using django :
select * from A , B , E where A.id = E.id and B.id = E.id and A.id = '107';
how i can do..?
A.objects().filter(e__aid=107)
geves me only content from A model.
Plzz Help..?
is there a way to query by row number in django. e.g. return row data of row #1?
Who else decided to learn about web development while in lockdown? :)
It's a great use of time :)
I am here trying to learn programming first time through web dev by this YT series. Awesome Videos
+1
+1
Me
When i wrote customers = Customer.object.all() and then print it
that what appeared ''
no names appeared so what is the problem??
A great explanation and a superb set of tutorials. One question. Could not an order have many products as opposed to just a single one in your example?
In this case no. Its a purchased item and not a set of orders. So lets say you place an order on amazon, you can have a shopping cart full of orders that relate to many products but each individual order must tie only to one product. You could however have quantity attribute. Is that what you were thinking?
@@DennisIvy Yes that was my idea. Again thanks for all the hard work on the tutorials.
Your welcome David :) it makes me very happy when I get feedback on everyone’s progress. Glad I can help :)
Thank you for everything dude! But we can't have access to the source code anymore plz fix it
How can I have more project based courses like these on Django? @Dennis Ivy. I'm up for paid courses.
I download your source code but It still has some error in queryDemos.py
Can you make one for uploading excel file and how to CRUD it in db
hey i can't save changes in the admin panel.my django version is 2.1.Can anyone help me?
13:15 will product.name work instead of product__name, both mean the same right?
can we use default dict for allOrders?
where is the link :P I had to search the documentation online
In this, order_set method not work plz you have any solutions tell me
'Customer' object has no attribute 'order_set' this error arrives when I test.Can someone please help me with that
hi
the source code link isn't working
sad, link is not working, i cant access the source code :(
why the links of the description of other materials never are in the description
😭
I didn't find the query cheatsheet in github.
Search this for the documentation QuerySet API reference
'Customer' object has no attribute 'order_set' this error arrives when i test
Doing a great job bro..................i have a doubt, which is the best database for django other than the default sqlite?
Definitely Postgres. Although you can use any database, Django was built with postgres in mind so integration is seamless. I’ll be making a video on how to do this soon :) and thank you for the support!
i'm getting an error working on the shell after print(customers)
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table:
Run
$ python manage.py migrate
I wonder how this SqlAlchemy handles thousands of data in real time projects, is this only option ?
Can you make a video on middlewares, context managers, Restful web API
Yep! Middleware and a rest API course are actually on my list of videos to do :)
Me a 35 yo male: haha peter piper initial are P, P.. Good tutorial series my man!
Hey Dennis just wanted to let you know that your source code link inst working...
Hi, are you going to address the complaints regarding the missing source code?
the code source is missing :(
how return the response to template
Your Source code + Live Demo Link Can't Work Please Check this problem
nice explanation sir tq ,query for students having equal marks how can give ranks by date of birth