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

preview_player
Показать описание

Django database querysets

Рекомендации по теме
Комментарии
Автор

Holy shit dude this might be the best tutorial series on any subject ever I have seen on Youtube (not just programming or web development)

jakeroosenbloom
Автор

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.

kken
Автор

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!

joaojesus
Автор

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 = 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 = Door")


#(9)***Order/Sort Objects by id
leastToGreatest =
greatestToLeast =


#(10) Returns all products with tag of "Sports": (Query Many to Many Fields)
productsFiltered =

'''
(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 =

#Returns total count for each product orderd
allOrders = {}

for order in
if order.product.name in allOrders:
+= 1
else:
= 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()

sangeethsubramoniam
Автор

Best django series on youtube. Learning a lot!! Thanks Dennis!!

reetamchatterjee
Автор

Dennis, I can't thank you enough! This "query_set" part was killing me! Even the Django documentation does not cover this topic properly!

LetCode
Автор

Very good your explanations, congratulations for the content and the prepared material.
Excellent quality!

luizzeduardo
Автор

I think this is best ever Django course in YouTube. You explain things simply! Thank for this course.

veyselaksin
Автор

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.

anishamalblanco
Автор

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.

kewartoscar
Автор

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.

ajaykjoshi
Автор

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

barscankurt
Автор

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.

akramnarejo
Автор

This tutorials is far better than many paid. to the point, precise theory concept before implementation

talha_anwar
Автор

Thank you sir clear all concept of Django.

mohammedqadir
Автор

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

philiponyeachonam
Автор

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

earljohncalizar
Автор

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 YouTube but has to do it on yours because of how good it is. Keep it up.

CraftscollectionCoUkshop
Автор

One of the smoothest tutorial set I've ever seen.. Thank you!

byabaci
Автор

Thanks Dennis, I really appreciate this series you created.

kevincampbell