Тёмный

Database Model Queries | Django (3.0) Crash Course Tutorials (pt 7) 

Dennis Ivy
Подписаться 214 тыс.
Просмотров 160 тыс.
50% 1

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 160   
@DennisIvy
@DennisIvy 2 месяца назад
Don't forget to check out my Complete Django course! dub.sh/NvGboTI
@sangeethsubramoniam3094
@sangeethsubramoniam3094 3 года назад
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()
@abdinasirmohamed8981
@abdinasirmohamed8981 3 месяца назад
thank you and i wish you the best
@kken8766
@kken8766 4 года назад
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.
@rokhribar5512
@rokhribar5512 4 года назад
Could you recommend a follow up course/site for us beginners after this crash course? Ty
@jakeroosenbloom
@jakeroosenbloom 4 года назад
Holy shit dude this might be the best tutorial series on any subject ever I have seen on RU-vid (not just programming or web development)
@DennisIvy
@DennisIvy 4 года назад
Haha thanks Jake :)
@ioan-alexandruilasi6987
@ioan-alexandruilasi6987 4 года назад
Who else decided to learn about web development while in lockdown? :)
@DennisIvy
@DennisIvy 4 года назад
It's a great use of time :)
@maniprasaddumre4403
@maniprasaddumre4403 4 года назад
I am here trying to learn programming first time through web dev by this YT series. Awesome Videos
@GauravKumar-lb6ze
@GauravKumar-lb6ze 4 года назад
+1
@NNote-zs6eo
@NNote-zs6eo 4 года назад
+1
@AnilSoni-mk9kx
@AnilSoni-mk9kx 4 года назад
Me
@luizzeduardo341
@luizzeduardo341 4 года назад
Very good your explanations, congratulations for the content and the prepared material. Excellent quality!
@DennisIvy
@DennisIvy 4 года назад
Thank you Luiz:)
@othmanechalal2401
@othmanechalal2401 Год назад
Thank you for everything dude! But we can't have access to the source code anymore plz fix it
@reetamchatterjee2179
@reetamchatterjee2179 4 года назад
Best django series on youtube. Learning a lot!! Thanks Dennis!!
@ettitaiwo1642
@ettitaiwo1642 Год назад
hi the source code link isn't working
@joaojesus8861
@joaojesus8861 3 года назад
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!
@axlblazeauthor
@axlblazeauthor Год назад
Hey Dennis just wanted to let you know that your source code link inst working...
@mohammedqadir3851
@mohammedqadir3851 4 года назад
Thank you sir clear all concept of Django.
@successsoi
@successsoi 4 года назад
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?
@Saketh-Chandra
@Saketh-Chandra 2 года назад
No need, Dennis is just showing examples.
@md.shariarkabir7350
@md.shariarkabir7350 4 года назад
I didn't find the query cheatsheet in github.
@abhi-rw5lt
@abhi-rw5lt Год назад
sad, link is not working, i cant access the source code :(
@dimpledivya2315
@dimpledivya2315 4 года назад
Its a very nice and useful video i like it must
@dimekarl4142
@dimekarl4142 4 года назад
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:
@beakmann
@beakmann 4 года назад
Run $ python manage.py migrate
@amolgode9843
@amolgode9843 2 года назад
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..?
@alieeldeenahmed2278
@alieeldeenahmed2278 4 года назад
When i wrote customers = Customer.object.all() and then print it that what appeared '' no names appeared so what is the problem??
@amiruldheen4819
@amiruldheen4819 5 месяцев назад
source code not available
@dorakadri476
@dorakadri476 Год назад
the code source is missing :(
@doungchansroeun766
@doungchansroeun766 3 года назад
how to get queriesDemos.py file?
@saidtahmazov9197
@saidtahmazov9197 2 года назад
Your series are just awesome, man! I do my best to support you with likes, subscruption, recommendations etc.
@ajaykjoshi
@ajaykjoshi 3 года назад
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.
@aydenkoperta6266
@aydenkoperta6266 4 года назад
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
@UmangDhandhania
@UmangDhandhania 4 года назад
How can I have more project based courses like these on Django? @Dennis Ivy. I'm up for paid courses.
@nguyenquang97
@nguyenquang97 4 года назад
I download your source code but It still has some error in queryDemos.py
@Copt774
@Copt774 2 месяца назад
This is great but how do I access the source code/files? I wanted to retrieve the query examples file but can't find it. Thanks!
@anishamalblanco7386
@anishamalblanco7386 3 года назад
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.
@naheanmahamud6391
@naheanmahamud6391 Год назад
Your Source code + Live Demo Link Can't Work Please Check this problem
@swasthiknayak5653
@swasthiknayak5653 3 года назад
There must be some youtube glitch, it's just showing me 89.3k subs. Please check it with the officials. :)
@fazliddinfayziev-qg1vg
@fazliddinfayziev-qg1vg 10 месяцев назад
Hi everybody, guys where can I find the source code. I am Query cheatsheet. Can you help me please ?
@louzynerd129
@louzynerd129 4 года назад
where is the link :P I had to search the documentation online
@JOAOFELIPEQUENTINO
@JOAOFELIPEQUENTINO 4 месяца назад
why the links of the description of other materials never are in the description 😭
@LetCode96666
@LetCode96666 4 года назад
Dennis, I can't thank you enough! This "query_set" part was killing me! Even the Django documentation does not cover this topic properly!
@dharshinim266
@dharshinim266 Год назад
'Customer' object has no attribute 'order_set' this error arrives when I test.Can someone please help me with that
@tokhenz
@tokhenz 11 месяцев назад
Hi, are you going to address the complaints regarding the missing source code?
@elnur_huseynov
@elnur_huseynov 3 года назад
WARNINGS: accounts.Customer: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. accounts.Order: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. accounts.Product: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. accounts.Tag: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. I'm getting this error can you help please
@luisdesousa1789
@luisdesousa1789 Год назад
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
@jaitungodhani2334
@jaitungodhani2334 3 года назад
In this, order_set method not work plz you have any solutions tell me
@HydoSkills
@HydoSkills 2 года назад
Me a 35 yo male: haha peter piper initial are P, P.. Good tutorial series my man!
@jaitungodhani2334
@jaitungodhani2334 3 года назад
'Customer' object has no attribute 'order_set' this error arrives when i test
@EltigreTafur
@EltigreTafur 4 года назад
Hola comunidad una pregunta como puedo pasar esta consulta sql a mi template desde la vista en forma de ciclo query = 'SELECT mantenimiento_mantenimiento.id ,mantenimiento_mantenimiento.phone , mantenimiento_mantenimiento.user , usuarios_user.first_name FROM mantenimiento_mantenimiento, usuarios_user where mantenimiento_mantenimiento.user = usuarios_user.id' #for list_art in Mantenimiento.objects.raw(query):
@sajawalsheraz6903
@sajawalsheraz6903 2 года назад
Hey i have send you an email from you website about a problem please help me there.
@louismefor9539
@louismefor9539 4 года назад
Hi dennis with regards to the query about "number of balls a customer has ordered" why have you used the double underscores whereas the relationship between a customer and an order is one to many relationship? this is the query i am referring to ballOrders = firstCustomer.order_set.filter(product__name="Ball").count()
@DennisIvy
@DennisIvy 4 года назад
Great question :) Double underscores can be used in many ways. In this case I use it to chain upwards and access an attribute of the product model (name). Because our query starts at customer we had to go three levels deep: Customer --> Order --> Product 1. We query all orders to that customers with "order_set.filter()" 2. Then we need to get all orders that are related to the product with the attribute of "ball" so we access the product.name by doing product__name in the "filter()" method. Sorry I hope that makes sense. Kind of tough to explain.
@louismefor9539
@louismefor9539 4 года назад
@@DennisIvy OK in other words you can use that for either many to many or many to one right?
@fasttrack4404
@fasttrack4404 3 года назад
how can i get all posts created by a user? via get_context_data() or get_queryset() i am new to your channel
@shishirantonyfernandis8454
@shishirantonyfernandis8454 4 года назад
Hey Denise, thank you for this tutorial, really helpful. Could you show how to create a customized id field in a model?
@DennisIvy
@DennisIvy 4 года назад
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 :)
@shishirantonyfernandis8454
@shishirantonyfernandis8454 4 года назад
@@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
@upgradenowutubechannel391
@upgradenowutubechannel391 4 года назад
You are doing so gooood! I hope you will be famous one day..just keep on working like that ❤👌👍
@DennisIvy
@DennisIvy 4 года назад
Haha I appreciate that :)
@lemorello6179
@lemorello6179 Год назад
Application error heroku
@earljohncalizar1154
@earljohncalizar1154 3 года назад
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
@shefat9892
@shefat9892 4 года назад
659 likes over against 1 dislike describe how gracefully you explained everything...
@pinakisingharoy202
@pinakisingharoy202 11 месяцев назад
your given Source code link is not opening.
@aswn18
@aswn18 2 года назад
13:15 will product.name work instead of product__name, both mean the same right?
@talha_anwar
@talha_anwar 4 года назад
This tutorials is far better than many paid. to the point, precise theory concept before implementation
@user1491
@user1491 2 года назад
Hello, I'm a little bit late ... but ... why does the query : product = Product.objects.filter(tags__name="Sports") --> works, but the query: item = Tag.objects.filter(tags__name="Ball") does not? Product and Tag are in a many to many relationship, so i thought, it wold work in both directions. >>> from accounts.models import * >>> item = Tag.objects.all() >>> print(item) >>> product = Product.objects.all() >>> print(product) >>> product = Product.objects.filter(tags__name="Sports") >>> print(product) >>> item = Tag.objects.filter(tags__name="Ball") Traceback (most recent call last): File "", line 1, in ....snipp.... django.core.exceptions.FieldError: Cannot resolve keyword 'tags' into field. Choices are: id, name, product >>> Thank you ...
@grzegorz-gregmika8339
@grzegorz-gregmika8339 4 года назад
Hope you never stop, great job! Think about document DB or Firebase
@DennisIvy
@DennisIvy 4 года назад
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 :)
@dawid_dahl
@dawid_dahl 3 года назад
Thank you so much! (Great little cheat sheet, too. Saved!)
@venkatrao235
@venkatrao235 2 года назад
nice explanation sir tq ,query for students having equal marks how can give ranks by date of birth
@avikumar9046
@avikumar9046 4 года назад
Sir your Videos are just Awesome thanks a lot..Love from India.
@MuhammadUsamaQamar
@MuhammadUsamaQamar 3 года назад
I'm gonna write your name in my Resume
@amanbhullar1908
@amanbhullar1908 4 года назад
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
@nakhan69
@nakhan69 2 года назад
K Ken I totally agree with you, I am a beginner and I find it very useful. Thank you Dennis
@yashraj67575
@yashraj67575 4 года назад
Hey Dennis, this goes to you... You have taught in the best way possible... KUDOS!!! 👌🙏
@medoune89
@medoune89 4 года назад
WAOUH !!!! VERY COMPLETE PLAYLIST for Beginner
@amanojha924
@amanojha924 2 года назад
Can you make one for uploading excel file and how to CRUD it in db
@l4m5
@l4m5 4 года назад
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
@DennisIvy
@DennisIvy 4 года назад
Putting this app on heroku soon, hopfully this week :)
@alinandrei9006
@alinandrei9006 4 года назад
I still haven't understood how you'd keep count of the number of the same product a customer has in a single order, without using the database.
@nishantpacharne1569
@nishantpacharne1569 4 года назад
Please Dennis make a series of Html Css and Bootstrap , please !!!! , and by the way you create awesome stuff !!
@AbdallahSallam88
@AbdallahSallam88 4 года назад
Search this for the documentation QuerySet API reference
@tanishtyagi1301
@tanishtyagi1301 3 года назад
is there a way to query by row number in django. e.g. return row data of row #1?
@axlblazeauthor
@axlblazeauthor 2 года назад
14:00 yeet
@veyselaksin
@veyselaksin 2 года назад
I think this is best ever Django course in RU-vid. You explain things simply! Thank for this course.
@llewellynhattingh3496
@llewellynhattingh3496 3 года назад
you are incredible! You deserve a nice cold beer! Thanks so much, helped me a lot
@eleighanneaveno655
@eleighanneaveno655 2 года назад
Thank you for these videos. I love this content so much!
@romit5867
@romit5867 4 года назад
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
@kishanpanchal5009
@kishanpanchal5009 4 года назад
bro this video is really cool and intrustinng thanks and i really appreciated for this type of presentation on Django,
@successpaulhart
@successpaulhart Год назад
thanks Mr dennis
@udbhavn8368
@udbhavn8368 4 года назад
Ohh man i finally found a good django course...Really love the effort you put into theses videos man...Amazing
@apolovzla_ccs
@apolovzla_ccs 4 года назад
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?
@binghamdt
@binghamdt 4 года назад
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?
@DennisIvy
@DennisIvy 4 года назад
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?
@binghamdt
@binghamdt 4 года назад
@@DennisIvy Yes that was my idea. Again thanks for all the hard work on the tutorials.
@DennisIvy
@DennisIvy 4 года назад
Your welcome David :) it makes me very happy when I get feedback on everyone’s progress. Glad I can help :)
@sagargahatraj5196
@sagargahatraj5196 4 года назад
hey dennis bro please show how to pull the data from many to many datas from table
@BardichTech
@BardichTech 2 года назад
Hi Dennis, thanks a lot for your effort and you're really a good instructor, good luck
@naimahmed8495
@naimahmed8495 4 года назад
hey i can't save changes in the admin panel.my django version is 2.1.Can anyone help me?
@uttarpustika
@uttarpustika 4 года назад
best explained thankyou
@kewartoscar8913
@kewartoscar8913 4 года назад
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.
@avitinformatics8221
@avitinformatics8221 4 года назад
I wonder how this SqlAlchemy handles thousands of data in real time projects, is this only option ?
@barscankurt4854
@barscankurt4854 3 года назад
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".
@EltigreTafur
@EltigreTafur 4 года назад
how return the response to template
@youcef659
@youcef659 4 года назад
I wanna thank you for your efforts and for the amazing videos you make with a very good explanation good luck
@mursalrabb6093
@mursalrabb6093 3 года назад
Definitely the best series on django @YT
@scattyrot
@scattyrot 3 года назад
can we use default dict for allOrders?
@CraftscollectionCoUkshop
@CraftscollectionCoUkshop 4 года назад
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 RU-vid but has to do it on yours because of how good it is. Keep it up.
@DennisIvy
@DennisIvy 4 года назад
Thank you :)
@kevincampbell256
@kevincampbell256 3 года назад
Thanks Dennis, I really appreciate this series you created.
@Nemosaur
@Nemosaur 3 года назад
Super helpful! Thanks so much!
@xochdt
@xochdt 4 года назад
I love how you teach. If it wasn't for you I'd probably wouldn't have followed my programing learning. Sincerly, thanks
@DennisIvy
@DennisIvy 4 года назад
Wow that inspires me! Thank you for taking the time to comment :) Best of luck
@hyperxelon2838
@hyperxelon2838 2 года назад
Your videos are awesome easy to understand
@ansariarbaz3374
@ansariarbaz3374 4 года назад
You know there are turns in life whereafter everything becomes smooth. Your vedios are like dat turn awesome dude..
@Magistrado1914
@Magistrado1914 4 года назад
Excellent course 12/07/2020
@RavinderSingh-un7ky
@RavinderSingh-un7ky 4 года назад
Can you make a video on middlewares, context managers, Restful web API
@DennisIvy
@DennisIvy 4 года назад
Yep! Middleware and a rest API course are actually on my list of videos to do :)
@sanjayshirodkar
@sanjayshirodkar 4 года назад
This course is the best ... I am learning so much doing this course. Thanks a ton Dennis.
Далее
МОЮ ТАЧКУ РАЗБИЛИ...!
39:06
Просмотров 428 тыс.