How Model Queries Work in Django

  Рет қаралды 95,895

Pretty Printed

Pretty Printed

Күн бұрын

Пікірлер: 160
@prettyprinted
@prettyprinted 4 жыл бұрын
Join my free course on working with the database and models in Django: prettyprinted.com/djangodata
@liorbm1
@liorbm1 4 жыл бұрын
Hi, You have a mistake: Slice[from : to : Step] - this is the correct Slice
@janekmuric
@janekmuric 6 жыл бұрын
The x[5:10] syntax simply means "get items from 5th index to 10th index". I don't know why you complicated it so much.
@Kamel419
@Kamel419 7 жыл бұрын
Thanks for all of your videos Anthony, great work as always! I've never understood Django's ORM
@prettyprinted
@prettyprinted 7 жыл бұрын
Thanks!
@digisocialmedia4403
@digisocialmedia4403 6 жыл бұрын
Where are the joins queries can you also tell that
@xtremehackerzpro9511
@xtremehackerzpro9511 7 жыл бұрын
It's would be nice to mention that exist OR statement in filtering over object for example: result = Item.objects.filter(item.creator = owner) | Item.objects.filter(item.moderated = False) Also great way in Django is a extracting year or month of date attribute for example: result = Item.objects.filter(date__created__year='2018') Keep going with great tutorial :)
@prettyprinted
@prettyprinted 7 жыл бұрын
Yeah, I completely forget about OR queries. I guess I'll have to cover them in a future video. Same thing with dates.
@blakef.8566
@blakef.8566 5 жыл бұрын
Thank you, much better than reading the documentation.
@prettyprinted
@prettyprinted 5 жыл бұрын
You're welcome! Thanks for watching.
@mekkismart7198
@mekkismart7198 4 жыл бұрын
Blake F. Reading the documentation is effective when you know the basics, the documentation is for advanced things
@Ccviewcom
@Ccviewcom 4 жыл бұрын
pretty smooth for a brazillian like me got easy to understand and pretty complete as you said!!! thank you so much sir, ill definitely recommend for coworkers and try the free course you said. Awesome!! keep going calm like this!!
@jomarsalazar2572
@jomarsalazar2572 5 жыл бұрын
Been looking for solution on how to combine tables in django for 2 days already. And I thank God i found your tutorial
@jomarsalazar2572
@jomarsalazar2572 5 жыл бұрын
can you help me pls how to combine 3 models?
@Elmaco7
@Elmaco7 5 жыл бұрын
Hi pretty printed. How can I create queries and view them on the site(when I do runserver) and not on the terminal's shell?
@hughe29
@hughe29 4 жыл бұрын
You need to put the query into your template.
@indianmongoose
@indianmongoose 3 жыл бұрын
Very clear and concise explanation , thank you !
@rajaryan7566
@rajaryan7566 4 жыл бұрын
sir you are the best teacher
@marthavanorshoven1942
@marthavanorshoven1942 4 жыл бұрын
This was VERY HELPFUL to me. I am new to Django and was wrestling with the query functionality
@prettyprinted
@prettyprinted 4 жыл бұрын
I'm glad it helped. Thanks for watching!
@sumanbanik3339
@sumanbanik3339 6 жыл бұрын
if its [:5], it simply means get the first five elements of the list, that is; 0,1,2,3,4....exclude 5, same with [5:10].
@meghashahri5527
@meghashahri5527 5 жыл бұрын
DO YOU HAVE VIDEO FOR QUERIES WITHOUT MODELS?
@buncha1499
@buncha1499 5 жыл бұрын
Thanks Pretty Printed! Very useful introduction for me. Love the ORM compared to raw SQL :)
@amolgode9843
@amolgode9843 3 жыл бұрын
Hello Sir...! 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..?
@GraceandWisdom
@GraceandWisdom 5 жыл бұрын
Just curious. What software app is being used for your command prompt? The one with the Reddish-Orange circle.
@prettyprinted
@prettyprinted 5 жыл бұрын
That's Ubuntu on Windows
@WaradeRahul121
@WaradeRahul121 4 жыл бұрын
Thank you. I appreciate your effort. 30 minutes back i was unsure how to understand querying a model in easy ways, you just :D ! Respect :)
@codewithkg9096
@codewithkg9096 4 жыл бұрын
Something I was looking for from long time!! Precious!
@mohaamiin8767
@mohaamiin8767 6 жыл бұрын
1:18 can you tell what that app is and what is used for plz
@prettyprinted
@prettyprinted 6 жыл бұрын
JADE. It's in the Chrome Chrome app store.
@mohaamiin8767
@mohaamiin8767 6 жыл бұрын
@@prettyprinted thanks can you make video how to use
@prettyprinted
@prettyprinted 6 жыл бұрын
Here you go: kzbin.info/www/bejne/gGqbeqeLZs-Fp5Y
@StevenSmith68828
@StevenSmith68828 4 жыл бұрын
Can you specify types? Like say that that age must be an int instead of a string
@suburbanblackboyradio2663
@suburbanblackboyradio2663 4 жыл бұрын
Awesome vid. I am just having an issue with using the & query. OR works just fine, but & is returning nothing and I'm stumped.
@pedrofolch9786
@pedrofolch9786 6 жыл бұрын
Thanks Anthony, this is very helpful, I need to know if and how can we save the results of the query into the same model or another model? Could you provide an example, Lets say using boolean field and a list of Integers to save the average of the list, if the boolean is True. Or do you have another video with that kind of example?
@prettyprinted
@prettyprinted 6 жыл бұрын
If I understand you correctly then all you'd need to do is check if that boolean is true before saving the model. If it doesn't true, then you don't have to do anything.
@MindJargon
@MindJargon 5 жыл бұрын
Hi. Would using model queries and using CRUD MySQL methods be different? Thanks
@KrishnaManohar8021
@KrishnaManohar8021 4 жыл бұрын
can you tell me how DateTime field u did?
@danielm3977
@danielm3977 5 жыл бұрын
Pretty Printed , briefly. It was awesome and well-articulated. THANk U
@Cam-p2z
@Cam-p2z 4 жыл бұрын
This video really helped me out a lot. Thanks!
@liorbm1
@liorbm1 4 жыл бұрын
We still using Postgres. Can you provide some output file that we can duplicate your DB ?
@ankurmishra8463
@ankurmishra8463 4 жыл бұрын
Hey, How we can query related to joins in django
@annettemaza3922
@annettemaza3922 6 жыл бұрын
Hi there! Thanks for the video! Is there a way to filter by next id? If I want to display the name of my next model on the current one? :)
@prettyprinted
@prettyprinted 6 жыл бұрын
I've never done something like that before. My approach would be to do it manually. Maybe this well help you: stackoverflow.com/questions/6021694/getting-next-and-previous-objects-in-django
@HawkwardPause
@HawkwardPause 6 жыл бұрын
Hi Anthony, can you filter from an offset all the way to the end of the table? i.e: Programmer.objects.all()[5:] in order to get the remainder? Thanks for these videos, they really help me focus down on the basics and remove roadblocks while I get used to Django.
@prettyprinted
@prettyprinted 6 жыл бұрын
If I understand you correctly, then yeah you can. An offset just skips the first n records. Limits to restrict the number of results, but with no limit, you'll get everything to the end.
@mikef6785
@mikef6785 2 жыл бұрын
How do you return a table value from a another user select table value. For instance returning firstName when selecting LastName from a People table. The value returned from the user selected lastName would populate a select field in a form. As well as the char field to hold the firstName after the user selects the lastName.
@olliewelsh123
@olliewelsh123 4 жыл бұрын
simple, clear and useful to beginners. thanks!
@sarveshwarpandey9516
@sarveshwarpandey9516 3 жыл бұрын
sir how to create model objects inside the code itself, not using shell or the admin panel
@yashwardhan9014
@yashwardhan9014 4 жыл бұрын
Is it possible to join two tables without using foreign key
@jafarhussain1304
@jafarhussain1304 4 жыл бұрын
how to get the id of the particular object for example i need the id of python in the language model can we get it directly if we can what is the syntax for it can u plz help me out
@jaydevpatil921
@jaydevpatil921 3 жыл бұрын
Your videos have been a great source of information. Actually I need to query a foreign data wrapper (foreign table) of my Postgres db using Django. Is there any way I could do that. Any leads would be highly appreciated. Thanks!!
@romanp1521
@romanp1521 4 жыл бұрын
where can I find all filters for queries
@nick_way
@nick_way 4 жыл бұрын
Very clearly explained, thank you
@dziurappa
@dziurappa 6 жыл бұрын
Hi Anthony ! Great tutorials ! Thanks a lot ! I have a problem which I can't solve by myself since I'm a beginner. For a example I'm making a website with some articles about dogs and cats. My question is: How to make some kind of button where USER (not admin) can select all the articles about dogs only. Where (which file) should I make a function with sql logic and how should I use it in .html ? Thank you in advance. Paul
@prettyprinted
@prettyprinted 6 жыл бұрын
You can start by creating two views. One for cats and one for dogs. In each view, you'll query for the category you want and return the results to some html template. Once you get that down, you should see the similarity between the two and you can think of ways you can combine the two views into one.
@ishikajain8114
@ishikajain8114 3 жыл бұрын
Thank you for the great explaination!
@nandrajmeshram8755
@nandrajmeshram8755 3 жыл бұрын
Very usefull stuff. Thank you! Please add query's using "in" fuction.
@bijarnia_vikash
@bijarnia_vikash 6 жыл бұрын
Django's pick up lines( easy way to get records) works well on Models. Thank you It was great.
@prettyprinted
@prettyprinted 6 жыл бұрын
Thanks for watching.
@darkdraconium
@darkdraconium 4 жыл бұрын
This was super helpful, thank you!
@180doman
@180doman 6 жыл бұрын
It would be great if you publish .sql file of your bases as well. Or fixture. Offcourse filling them by hand can be good excercise but in case of Programmers table it can be quite daunting task. Other than that - awesome tutorial!
@prettyprinted
@prettyprinted 6 жыл бұрын
I forgot to add the code link. You can download it here: s3.us-east-2.amazonaws.com/prettyprinted/django_model_queries.zip
@santanasta82
@santanasta82 7 жыл бұрын
Great video again, Anthony! Thanks for your videos! Please keep on doing! One doubt: what is the program you use to see your database tables? Is that JADE? Where can I get it? I like the way you check your database. Thanks man! Congratulations!
@prettyprinted
@prettyprinted 7 жыл бұрын
Yeah, that's JADE. You can get it in the Chrome web store here: chrome.google.com/webstore/detail/javascript-based-database/bponbdjkefbmgkfiiphhabghkkfocook?hl=en
@santanasta82
@santanasta82 7 жыл бұрын
Perfect! Thank you very much! I love it!
@deepakprakash8940
@deepakprakash8940 6 жыл бұрын
Hey great and nice video for basics but how you were clearing the shell so quickly was that some trick or shortcut plz share
@prettyprinted
@prettyprinted 6 жыл бұрын
ctrl + l
@deepakprakash8940
@deepakprakash8940 6 жыл бұрын
Thanks a lot
@EpoKeins
@EpoKeins 3 жыл бұрын
Can someone tell me where to find all these filter keywords (in the documentation)?
@sumitmishra848
@sumitmishra848 4 жыл бұрын
very helpful stuffs . THANKS A LOT !!!
@azamatuzbekov117
@azamatuzbekov117 5 жыл бұрын
I'm wondering when we upload data to db should we enter ID or name itself? For example Programmer table column Language. Do you have any videos related to this?
@prettyprinted
@prettyprinted 5 жыл бұрын
It depends on your situation. For the most part, I like IDs better, but names can work too if they're unique.
@anthonyhumphreys9680
@anthonyhumphreys9680 3 жыл бұрын
dang bro ur awsome thank you for all your content
@shadiismailalzouabi1035
@shadiismailalzouabi1035 4 жыл бұрын
lPlease sir, python.programmers_set this command create many to many relationship between programmers module and ( programme language ) module?
@muhsinkhalif3621
@muhsinkhalif3621 5 жыл бұрын
Thanks bro such a helpful video!
@prettyprinted
@prettyprinted 5 жыл бұрын
You're welcome! Thanks for watching.
@Fire_Fly_101
@Fire_Fly_101 5 жыл бұрын
Pretty good info bro .. you have really helped me a lot in my personal project.. your videos are actually really informative n helpful..!!!
@prettyprinted
@prettyprinted 5 жыл бұрын
I'm glad my videos have helped you. Thanks for watching!
@ChaosArtist
@ChaosArtist 5 жыл бұрын
Nice overview, very helpful to see the most common Django model queries.
@harshthakkar8081
@harshthakkar8081 4 жыл бұрын
can we use startwith = '[a-z]' like this ??
@mostafizurrahmanshohan9075
@mostafizurrahmanshohan9075 6 жыл бұрын
Thank you... can u show us how we can make class-based URL slug?
@prettyprinted
@prettyprinted 6 жыл бұрын
I'll add that to my list. Thanks for the idea.
@shubhangidutt5080
@shubhangidutt5080 3 жыл бұрын
In my project. Objects.all() is throwing error Please help
@sushilraverkar007
@sushilraverkar007 4 жыл бұрын
Why objects.all() not giving all columns ?
@betelhemtesfaye7838
@betelhemtesfaye7838 3 жыл бұрын
Thank you Sir. You are the best.
@MrDevZero
@MrDevZero 5 жыл бұрын
Thank you. Very helpful.
@prettyprinted
@prettyprinted 5 жыл бұрын
You're welcome! Thanks for watching.
@neelesh.vishwakarma
@neelesh.vishwakarma 5 жыл бұрын
I'm getting an error in the following expression Message.objects.filter(ishandled == True) 'ishandled' is a field in the Message table and I'm getting error that ishandled is not defined. can you please help?
@prettyprinted
@prettyprinted 5 жыл бұрын
One equals sign instead of two.
@as-youtuber6215
@as-youtuber6215 5 жыл бұрын
Any video regarding django ORM joins????
@prettyprinted
@prettyprinted 5 жыл бұрын
Not yet, I'll consider making a video on that.
@santoshkumar-xq6wx
@santoshkumar-xq6wx 4 жыл бұрын
Nice vedio, thanks for making our work more easy, can you say how to user "OR" filter here.
@JS-lw4ks
@JS-lw4ks 4 жыл бұрын
Does anyone have any resources on connecting to an MSSQL database? I can connect to the DB and run a stored procedure but struggling with parameters
@AliHasanov
@AliHasanov 4 жыл бұрын
Probably, you forgot : First object: Model.objects.filter("name").first() Last object: Model.objects.filter("name").last() To get random objects: Model.objects.order_by('?') and Q objects for complex lookups Thanks for everything :)
@kakumbanassirissa3972
@kakumbanassirissa3972 5 жыл бұрын
Thanks for the video i however tried to filter a column from one of my models which has a foreign key but i had to reference it with the primary key instead of the real word. is there a way i can look up for something with out using the primary key. for example Programmer.objects.filter(company__exact='Microsoft') - returned the error but Programmer.objects.filter(company__exact='1') where 1 is the primary key Id for microsoft return no errors how can i make the first statement work. Note: i just used the above example thanks
@prettyprinted
@prettyprinted 5 жыл бұрын
You would use __ to get into the child model. So company__name__exact='Microsoft'
@kakumbanassirissa3972
@kakumbanassirissa3972 5 жыл бұрын
​@@prettyprinted Thanks will try that and revert. do u have any videos on writing templates?
@prettyprinted
@prettyprinted 5 жыл бұрын
@@kakumbanassirissa3972 Check out my Jinja playlist. It's for Flask, but it's very similar to the default Django template language.
@kakumbanassirissa3972
@kakumbanassirissa3972 5 жыл бұрын
Pretty Printed thanks
@shiv77patil
@shiv77patil 6 жыл бұрын
can u help me i querying foreignkey
@junaidtariq3265
@junaidtariq3265 4 жыл бұрын
I have three table a,b,c. A have many to many relation with b and b have many to many relation to c. I have problem when I click on a its show all relative b but I want when I click on a it will show b table entries and all c entries which relative to b
@harshraj22_
@harshraj22_ 5 жыл бұрын
Thanks A Lot ! The video was very helpful 😁😊 Do you have any video explaining more about foreign keys ? It seems little confusing ☹️
@nowyouknow2249
@nowyouknow2249 4 жыл бұрын
Very useful Thanks
@harpalsinhjadeja2568
@harpalsinhjadeja2568 6 жыл бұрын
how am i supposed to run sql queries in shell like lets say i want to insert then how do i insert something in the table using sql in django shell
@prettyprinted
@prettyprinted 6 жыл бұрын
Here's more information on that: docs.djangoproject.com/en/2.1/topics/db/sql/#executing-custom-sql-directly
@manishkumar-db5xm
@manishkumar-db5xm 5 жыл бұрын
Very useful video, Thanks
@prettyprinted
@prettyprinted 5 жыл бұрын
You're welcome!
@AnimatedHooman
@AnimatedHooman 6 жыл бұрын
Amazing video sir. Very informative
@pranavkhandelwal8474
@pranavkhandelwal8474 5 жыл бұрын
Simple and Good Explanation :)
@RizwanAli-bu5oy
@RizwanAli-bu5oy 6 жыл бұрын
how can i retrieve database tables and all the the data from mysql. if you like, make me a video on mysql, i'm using xampp server. please give me all the details about mysql and how to query data. i have made database using phpmyadmin, now i want to use that data in django app
@AjaySharma-jv6qn
@AjaySharma-jv6qn 5 жыл бұрын
Thanks for your work
@mrmuranga
@mrmuranga 5 жыл бұрын
well explained...thank you
@victorkeynote6301
@victorkeynote6301 6 жыл бұрын
works the same, if i use filter.name, instead of filter.name__exact. so why not just use name??
@prettyprinted
@prettyprinted 6 жыл бұрын
You don't have to. I'm not sure why I did it here. Sometimes I get tunnel vision.
@alnoneatall
@alnoneatall 3 жыл бұрын
any Project with django sir?
@shashidhardevraj
@shashidhardevraj 6 жыл бұрын
Thanks for the video! Its very clear.
@prettyprinted
@prettyprinted 6 жыл бұрын
You're welcome!
@ROMAN-zu3wu
@ROMAN-zu3wu 2 жыл бұрын
Thank u so much bro
@glassy5716
@glassy5716 3 жыл бұрын
thanks Great video
@mzgz4216
@mzgz4216 7 жыл бұрын
Great video thanks Anthony
@prettyprinted
@prettyprinted 7 жыл бұрын
Thanks for watching!
@naimurrahman2367
@naimurrahman2367 5 жыл бұрын
can anyone help to solve this ImportError: cannot import name 'get_user_object' from 'django.contrib.auth'
@Smoonwalkerm
@Smoonwalkerm 6 жыл бұрын
When I type Company.objects.all().. I'm getting this: ....Why not the names of companies ?
@prettyprinted
@prettyprinted 6 жыл бұрын
You have to define __str__ in your model class.
@aniketmlk6
@aniketmlk6 5 жыл бұрын
Thanks! Extremely High quality content
@prettyprinted
@prettyprinted 5 жыл бұрын
Thanks for watching!
@taihatranduc8613
@taihatranduc8613 3 жыл бұрын
It's a very good video
@footballfan7796
@footballfan7796 6 жыл бұрын
Hey can I email you need your help in creating something I been using django for some time now and want to test out my skills but I got stuck and don't know how to move on so I hope you can help me thank you
@prettyprinted
@prettyprinted 6 жыл бұрын
I might be able to help. My email is anthony@prettyprinted.com
@footballfan7796
@footballfan7796 6 жыл бұрын
@@prettyprinted ok i will message you now thanks
@xtremehackerzpro9511
@xtremehackerzpro9511 7 жыл бұрын
Great video again... Go ahead :)
@prettyprinted
@prettyprinted 7 жыл бұрын
Thanks for watching!
@rvenu8932
@rvenu8932 5 жыл бұрын
super brooooooo Exlente
@saharamanson1970
@saharamanson1970 4 жыл бұрын
thanks bro..
@nehalbhosale5663
@nehalbhosale5663 3 жыл бұрын
Grt ❣️❣️❣️❣️
@keerthivasang1178
@keerthivasang1178 6 жыл бұрын
Thank U very much sir!!!!!!!!
@prettyprinted
@prettyprinted 6 жыл бұрын
You're welcome! Thanks for watching.
@nickt423
@nickt423 5 жыл бұрын
I didnt watch the full video because some reason this is hard to follow along without the IDE. views.py, models.py, ect. dont matter here?
@prettyprinted
@prettyprinted 5 жыл бұрын
The video covers the basics of the queries, so I use the console instead of the web app so you can see the results instantly. But when you're creating a real app, you'd use the same statements within your views.py file as you do in the console here.
@bastiaanvandenabeele8645
@bastiaanvandenabeele8645 6 жыл бұрын
Thanks !
@prettyprinted
@prettyprinted 6 жыл бұрын
You're welcome! Thanks for watching.
@BehruzbekOtayev
@BehruzbekOtayev 4 жыл бұрын
Why do you call it 'Jango'? Its with D 'Django'.
@KaranKumar-wb5bn
@KaranKumar-wb5bn 4 жыл бұрын
I love you🖤
@prettyprinted
@prettyprinted 4 жыл бұрын
I love you too 😘
@openmindjustdoit1306
@openmindjustdoit1306 3 жыл бұрын
mypost=post.objects.filter(id__topboard=self).count() print(mypost) return mypost i want to get acount all post for this board get Error like this >>>> ValueError at / Cannot query "Schoole": Must be "topic" instance.
@jarettchaiken1492
@jarettchaiken1492 6 жыл бұрын
name__exact and name__iexact are doing the same thing for me. >>> Language.objects.filter(name__exact='Java') >>> Language.objects.filter(name__iexact='Java')
@shreyesbasutkar9206
@shreyesbasutkar9206 5 жыл бұрын
how to add values of 2 objects? say suppose age .. i want to add 2 people age .. how can i do it?
Use Django to Create a Todo List App
36:59
Pretty Printed
Рет қаралды 68 М.
Understanding Django Model Relationships
25:56
Pretty Printed
Рет қаралды 95 М.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Learn the Basics of Django Signals
22:37
Matt Freire
Рет қаралды 50 М.
Learn the basics of Django's Model Managers and Querysets
19:38
Matt Freire
Рет қаралды 44 М.
The Basics of Django Models
37:32
Pretty Printed
Рет қаралды 99 М.
Django Authentication Basics
19:38
Pretty Printed
Рет қаралды 109 М.
Getting Started With Django All Auth
19:01
Pretty Printed
Рет қаралды 13 М.
Django Rest Framework | Serializers & CRUD
22:40
Dennis Ivy
Рет қаралды 393 М.
How to Handle User Authentication in Django
26:39
Matt Freire
Рет қаралды 86 М.
Django + Chart.js // Learn to intergrate Chart.js with Django
26:45
CodingEntrepreneurs
Рет қаралды 232 М.
Creating Forms From Models in Django With ModelForm
11:40
Pretty Printed
Рет қаралды 47 М.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН