exactly ... This is second time I going through corey sir videos and cant tell how easy django looks to me ... Thanks millions and zillions to corey sir ....
I appreciate that you don't cut out when you do mistakes. I think it's important for beginners like me to see how you debug them and that even a professional like you can have a typo. Great videos. Thanks a lot!
Corey, there is a serious lack of quality Django tutorials out there. You are the only one pumping them out. Your series is incredible. I know you must be busy with so many project ideas already, but could you try extending this series into an advanced series next? I feel like I've learned a lot, but I would like to see you tinker around with the styling, or integrating new apps from Django Packages. I still don't feel fully confident in straying off the path you've laid out for us. I'm sure there are many others like me who would love to see more examples of customization now. I also looked into Mezzanine and Wagtail as CMS options, but again, there are very few tutorials on either of those platforms either. If you're ever looking for other ideas for further series, maybe one on using a CMS would be cool too :). You're the best man, and I'm going to forever point people looking to learn python, to your RUclips.
I really enjoy how you not only show how to do things, but explain some of the processes behind the operations. If gives inspiration for other creative ideas and uses.
Oh I get stuck for hours on mistakes all the time. It just doesn’t seem that way in the videos because I’ll edit them out to save viewers time. But it definitely happens
Probably the best tutorials on Django. Thanks-a-lot Corey, your content is not less than magic simple, detailed and obviously well explained. Thanks a-lot.
Corey. Your tutorials are premium quality. Anyone who says otherwise is just insane. I would love it if you can make a tutorial on how you learn(Especially going through documentation) because I don't know how you dig out some deep concepts but I would love to learn.
Big thumb up for all this tutorial ! It's really simple and clear to understand ! For those like me who are using django in version > 3, for the order_by in the get_queryset method, we need to do it before the filter call like : >
Many times I refused to watch youtube tutorials because I think that they are useless.Today I watched your 11 videos continuously thank you I wish you will get a fair shot :)
Thanks for this Corey :) I tried to add a functionality to display all my post by visiting my profile page and clicking the profile picture. :) And successfully done it. Hehe So proud of myself. Thanks Corey sir. :) Just sharing. Hehe
I may have downloaded your c. 80 videos using youtube-dl but I'm still coming back to hit that like button, you're a saint to aspiring devs everywhere, keep it up!
You making videos with an actual sense of spreading knowledge instead of buying likes and shares. One of the best Django tutorials available on internet. Thankyou from Germany.
I spent 2 hours figuring out it was supposed to be get_queryset() not get_query_set() and just when I planned on sharing this valuable info in comments, as I moved ahead of video to get the screen he explained this. Oh god.. don,t know if jumping ahead is good or bad anymore.:( But greatful for the content Corey. Almost everything I know in Django is because of you. Thank you.
For those that are having trouble with adding the extra posts from the posts.json, make sure you have the user id exists for id 1 and id 2 and you did not delete that user. You can check with this command in the shell: from django.contrib.auth.models import User User.objects.get(id=1) # make sure this returns a user User.objects.get(id=2) # make sure this returns a user If no user is returned, make a new user with the : User.objects.create_user(username='missing', email='missing@email.com', password='testing321', id=) Hope this helps. Corey is the bomb.
it gives an error of TypeError: Profile.save() got an unexpected keyword argument 'force_insert' I just edited the json file to go around that. For now
This whole tutorial series is beast mode. It would be amazing if you could make a tutorial series on building a simple ML app. Something like the user gives some text input and the output is some sentiment score or something using scikit-learn, tensor flow, or pytorch. I would love to see how you would design the layout of that kind of website/web-app using Django.
YOOOOO!! My dream just came true. I like the video at 2.9k likes and made it 3k. Lets GO! I am just 14, but Corey Schafer you are amazing. Thank you so much for these videos and I am truly thankful that you are helping me further my programming journey. Thank you so much!
Honestly Bro! I was doing your django series after that I took udemy course and realised that first two projects were real shit. Got only 2 to 3 different pieces of information from those udemy videos. Did your series again and understood the concepts in more clearity. You are the only one out there carrying this quality stuff out there. There is serious lack of quality stuff out there. It would be very helpful if you could make a course on DJANGO REST FRAMEWORK. Need guidance in that part. Thank you for everything you are doing for us and we also make sure that we will watch all the ads and visit the pages as a support to this channel. Love for your dog from India.
No words to say beyond other viewer comments! Creating personal Operations Manual step by step for a foundation of future projects thanks to you! Ready to complete this and dive into other topics by you...!
1:40 getting data from json in shell 4:45 Paginator 8:45 using Paginator with class based view (CBV) 11:30 adding pagination UI in templates 23:00 filtered data Paginator with class based view (CBV) get_queryset 25:05 get_object_or_404
You are love, Thank's for making Django easy for us, I will never able to complete my final year project(B.Sc) without your loving playlist of Django, it helped me a lot
For anyone stuck with pagination, yeah, this changed in newer versions of django. with Django 3.0 i get pagination on the users-post page, but the not post page itself. As corey said, this part of the code is not DRY(repeated code in both html files regarding actual pagination) but still they behave differently.
Thank you so much for this video!!! I was stuck on this problem from a long time and was thinking to apply concept of Lazy Loading, but this solves my problem. Thankyou!
At 22:00 in the end of paginations. I did some changes on the pagination buttons I hope you like it: {% if is_paginated %} {% if page_obj.has_previous %} First Previous {% else %} First Previous {% endif %} {% for num in page_obj.paginator.page_range %} {% if page_obj.number == num %} {{ num }} {% elif not page_obj.has_previous %} {% if num = page_obj.number|add:'-2' %} {{ num }} {% endif %} {% elif num >= page_obj.number|add:'-1' and num
Hi Marcelo, this part is not right I'm afraid {% else %} First Previous {% endif %} because it will be visible even if there isn't a previous page, which should not be the case. same with this: {% else %} Next Last {% endif %} it will appear even when there isn't a next page. Also, their href attributes are '#', meaning they will not change to a particular page
@@shemmuthanga6352 To be honest I don't know exactly what's going on in that piece of code, but anyway, here's what i meant with this code: I wanted the buttons to appear even if there is no previous page before the first one and even if there is no later page after the last one.
And to avoid confusion I changed the colors by changing the class from "btn btn-outline-info mb-4" to "btn btn-outline-secondary mb-4". Try it in your django code see what you think :P
After overriding the save function in users/models.py I was unable to create new users. a fix to this was changing: def save(self): super().save() to: def save(self, *args, **kwargs): super().save(*args, **kwargs) Hope it helps somebody! Thank you for everything that you do Corey. Keep it up. Your tutorial has restored my motivation!
The save method update solved creation of Profile Problem but new error generates saying default.jpg doesn't exists in media folder even though it exists. Tried even restating the development server . problem still persists
To anyone getting an error when creating posts: I have noticed there is a small error maybe due to changing of Django versions When creating posts, providing author_id = post['user_id'] gives an error. Just do a user = User.objects.get(id=post['user_id']) before making the post and instead of author_id, do author = user. Of course you will need to import User model as explained in previous videos.
@@alexkoshy1999 No bro no need to add gibberish post its not good practice this is how i identify my users id from shell , because at the first i have created some users and deleted for some resons thats why i has been facing this issue here is the shell code which i have used >>> user = User.objects.all() >>> user >>> user = user.first() >>> user >>> user.id 9 >>> user = User.objects.all() >>> user >>> user = User.objects.get(username='NewUser') >>> user >>> user.id 10 >>> i hope this would help
I found this tutorial to be pretty helpful, thank you. I was wondering if you will do another part on many-to-many relationships for models particularly in relation to CRUD. Maybe for example for your blogs, you can have tags.
Hi corey, this entier tutorial is incridible and understandable , but can you extend this series a bit and let us know how to implement chat feature so that users can chat as well after logging in
I was unable to to add he posts.json using the import json... I have a Mid 2010 macbook pro laptop for what it's worth. I'd like to add those addiional profiles if possible.
Corey, if you could bottle this and sell it... but then, you're probably already rich from working as a programmer. It would be pretty cool if you could find someone who knows as much as you do--but about other computer topics, then teach them how to plan a recording session. You could sell it as a documentation service to companies with products like Django and Git. Anthony Sherrill says you don't edit your mistakes out, but the vast majority of them appear to be planned mistakes--not mistakes at all. I was using another set of tutorials, but that guy wasted oodles of time just chit chatting. I love the way you plan, follow your plan, and get to the next point.
I perform a lot of edits on my videos. I'll leave mistakes in if I feel like they have some value to the viewer, but if they are mistakes that won't give any value then I try to edit them out.
@4:08 well, could you please please show how to add images to posts, I was thinking about django-ckeditor, or maybe just a simple form one image per post plus thumbnail in the listview on home.html along with search section would spice up the blog even further. Thank you for this tutorial, it's great!
To any of you who get an error of django.db.utils.IntegrityError: FOREIGN KEY constraint failed. That can be happening for some reasons (most of them are detailed in the comments), but I didn't see any comment addressing the problem I had. Because I played with the creation of the user a little bit, my user_ids weren't 1, 2, and 3. However, the JSON file contains user_id of 1, 2, and 3, so I basically tried to upload a post to an unexisting user. To check the user_id of each user you can do the following: from django.contrib.auth.models import User users = User.objects.all() for user in users: print(user.id) After that, you need to update the user_id in the JSON file to one of the numbers you have. Hope it helps!
after loading the JSON file and saving every post in it I am getting a django.db.utils.IntegrityError: FOREIGN KEY constraint failed Error please help me with this issue
having error because of user_id value.. in database user_id for each user doesn't restore if you delete a user from database. I mean if you delete a user whose user_id was 2, if you create new user, then index 2 will not be assigned to any user, it will remain null and new_user id will be 3.
As pointed out: Whenever you delete and create a new user, primary key (pk) and user id (id) will continue and not be reset. Therefore, if you followed the tutorial, chances are high you don't have users with id 2 anymore. Hence, in posts.json you need to replace id 2 with a corresponding value. To find good id values you need to query the db. First, open a shell: python manage.py shell Second, in the Python shell run these commands to find all ids of all users: from django.contrib.auth.models import User users = User.objects.all() for user in users: print(user.id) Third, in posts.json replace the ids with valid ids from your db.
How do I know I can use 'author_id' for the models.Post at 2:54 ? Unfortunately I didn't find anything about this term in the docs. But it seems like everyone uses it. How do I know which kind of keywords (like 'author_id' in this case or 'paginate_by' at 8:53 or 'page_obj' at 12:30) I can use? Btw. 'author.id' would seem more logically for me.
I would like to inform you guys, instead of using get_query_set function, it should be get_queryset function (only one underscore '_') to successfully filter out the username in counting the number of post and display its posts. I don't know if it has something to do with the django versioning but, if you were using get_query_set function, it will not work. Sir Corey, please double check this. Thankss! Anyone correct if i'm wrong - 24:39
I have question if anyone can answer, how to get familiar with all these methods. We can't remember all these methods right? Where to check for them if we forgot ? Great Series Corey. I am learning more from you than my university lecturers. And thank you!! AS Soon AS I will get my first job, I am gonna contribute to your channel through patreon.
I have a problem with posts ordered by author. Like in your video in 33:15 to 33:45 I get all posts(12) even after small changes in views.py like getqueryset. I noticed that when I click on the user id it getting user id from Url but the first posts that I see are mine and then I see the users posts no matter which user I chose(they are always sorted by Me>NewUser>NewUser2>NewUser3). I also didn't use JSON file with posts but make them through the page and maybe it cause some problems(also sorry for my bad English xd).
14:10 When accessing an attribute in the page object to make a button for a previous page, we use page_obj.previous_page_number Isn't this a method? Why don't we give it () page_obj.previous_page_number()
Thanks for this tutorial, I really enjoy the way you teach. But I have a problem with the if elif statement in home.html: throws this error :"TemplateSyntaxError at / Invalid block tag on line 32: 'elif', expected 'empty' or 'endfor'. Did you forget to register or load this tag?" I've bee through my code several times, even erased that part and started all over again, checked all my templates, but not working... any idea? thanks
That small heart attack you get when you test something and it doesn't work because you swear you followed the instructions but then it turns out Corey made the same mistake and it's fixed 2 minutes later.
The registration and profile create worked fine during Part 8 as we were building the code. Now in Part 11, I tried to register a new user, and it failed. Seems Django does not like form.save() in the register "view.save() got an unexpected keyword argument 'force_insert". Not sure if the class based views did something. I user is created but then you also get a "user has not profile error". The user is added to the admin, and you can create a profile in the admin manually. Thoughts ???????
if anyone is following this tutorial at the date of this comment and having trouble with the json file, you can: from django.contrib.auth.models import User and then modify the query a bit i did for p in posts_json: post = Post(title=p['title'], content=p['content'], author=User.objects.get(pk=p['user_id'])) post.save() django expects a user object instead of just the primary key, at least in django 4.2.1 which is what I'm using.
I'm getting: TemplateSyntaxError at / Invalid block tag on line 32: 'elif', expected 'empty' or 'endfor'. Did you forget to register or load this tag? on line 11: {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %} Not sure how to fix this. I try copying directly from your files on github but still getting this issue.
Hello Corey ! Thank you for this Nice Tutorial. But i Can not Understand "view.kwargs.username " the Line 3 of blog/user_posts.html . where the view comes form? Can you explain it plz.. ?
for pagination when i created another user, the profile of the new user is not being created instead an error message is thrown which says - save() got an unexpected keyword argument 'force_insert
There is an issue with the code in this video that I fixed in the later videos. If you're getting an error that says something like "save() got an unexpected keyword argument 'force_insert'" then please update the save method in users/models.py to the following: def save(self, *args, **kwargs): super().save(*args, **kwargs)
views.kwargs means : kwargs stands for keyword arguments. It is a lookups on dictionary in template. Referring to the function get_queryset inside {view.py .... username=self.kwargs.get('username'} file. Basically, it is asking the function get_queryset from view.py file to pass the username as an argument to it. view.kwargs.username Please Corey correct me if i'm wrong?
Foreign keys are converted to _id by django ORM: root@root SocialApp % python3 manage.py sqlmigrate blog 0001 BEGIN; -- -- Create model Post -- CREATE TABLE "blog_post" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(100) NOT NULL, "contect" text NOT NULL, "date_posted" datetime NOT NULL, "author_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED); CREATE INDEX "blog_post_author_id_dd7a8485" ON "blog_post" ("author_id"); COMMIT;
Corey: "And Django makes this easy for us."
Me: "No, you make this easy for us :)"
nice
EXACTLY
exactly ... This is second time I going through corey sir videos and cant tell how easy django looks to me ... Thanks millions and zillions to corey sir ....
sooo true
I appreciate that you don't cut out when you do mistakes. I think it's important for beginners like me to see how you debug them and that even a professional like you can have a typo. Great videos. Thanks a lot!
Corey, there is a serious lack of quality Django tutorials out there. You are the only one pumping them out. Your series is incredible. I know you must be busy with so many project ideas already, but could you try extending this series into an advanced series next? I feel like I've learned a lot, but I would like to see you tinker around with the styling, or integrating new apps from Django Packages. I still don't feel fully confident in straying off the path you've laid out for us. I'm sure there are many others like me who would love to see more examples of customization now. I also looked into Mezzanine and Wagtail as CMS options, but again, there are very few tutorials on either of those platforms either. If you're ever looking for other ideas for further series, maybe one on using a CMS would be cool too :). You're the best man, and I'm going to forever point people looking to learn python, to your RUclips.
I really enjoy how you not only show how to do things, but explain some of the processes behind the operations. If gives inspiration for other creative ideas and uses.
I really like it when Corey fids a mistake and fix it in seconds
I spend hours debugging an indentation
Oh I get stuck for hours on mistakes all the time. It just doesn’t seem that way in the videos because I’ll edit them out to save viewers time. But it definitely happens
Probably the best tutorials on Django. Thanks-a-lot Corey, your content is not less than magic simple, detailed and obviously well explained. Thanks a-lot.
Corey. Your tutorials are premium quality. Anyone who says otherwise is just insane. I would love it if you can make a tutorial on how you learn(Especially going through documentation) because I don't know how you dig out some deep concepts but I would love to learn.
Big thumb up for all this tutorial ! It's really simple and clear to understand !
For those like me who are using django in version > 3, for the order_by in the get_queryset method, we need to do it before the filter call like :
>
Doing it the way he did in the tutorial worked fine for me. Django 4.2.3 🤷♂
Many times I refused to watch youtube tutorials because I think that they are useless.Today I watched your 11 videos continuously thank you I wish you will get a fair shot :)
Thanks!
Thanks for this Corey :)
I tried to add a functionality to display all my post by visiting my profile page and clicking the profile picture. :) And successfully done it. Hehe So proud of myself. Thanks Corey sir. :) Just sharing. Hehe
I may have downloaded your c. 80 videos using youtube-dl but I'm still coming back to hit that like button, you're a saint to aspiring devs everywhere, keep it up!
You making videos with an actual sense of spreading knowledge instead of buying likes and shares. One of the best Django tutorials available on internet. Thankyou from Germany.
With 10 videos you taught me the basics of Django. You are awesome. Thank you very much!
I spent 2 hours figuring out it was supposed to be get_queryset() not get_query_set() and just when I planned on sharing this valuable info in comments, as I moved ahead of video to get the screen he explained this. Oh god.. don,t know if jumping ahead is good or bad anymore.:( But greatful for the content Corey. Almost everything I know in Django is because of you. Thank you.
For those that are having trouble with adding the extra posts from the posts.json, make sure you have the user id exists for id 1 and id 2 and you did not delete that user.
You can check with this command in the shell:
from django.contrib.auth.models import User
User.objects.get(id=1) # make sure this returns a user
User.objects.get(id=2) # make sure this returns a user
If no user is returned, make a new user with the :
User.objects.create_user(username='missing', email='missing@email.com', password='testing321', id=)
Hope this helps. Corey is the bomb.
TY!!!!!!!
it gives an error of TypeError: Profile.save() got an unexpected keyword argument 'force_insert'
I just edited the json file to go around that. For now
I would love to see a part 2 of this series
there is a Part 2 of this series. You are currently on Part 11
@@sarthakbhutani7413 Where can i find it?
please help
@@bentwite3093 hes joking
He means Season 2, lol
This whole tutorial series is beast mode. It would be amazing if you could make a tutorial series on building a simple ML app. Something like the user gives some text input and the output is some sentiment score or something using scikit-learn, tensor flow, or pytorch. I would love to see how you would design the layout of that kind of website/web-app using Django.
YOOOOO!! My dream just came true. I like the video at 2.9k likes and made it 3k. Lets GO! I am just 14, but Corey Schafer you are amazing. Thank you so much for these videos and I am truly thankful that you are helping me further my programming journey. Thank you so much!
Nice! Thanks!
You are the only person who can teach complicated stuff in most simplest way.
Honestly Bro! I was doing your django series after that I took udemy course and realised that first two projects were real shit. Got only 2 to 3 different pieces of information from those udemy videos. Did your series again and understood the concepts in more clearity.
You are the only one out there carrying this quality stuff out there.
There is serious lack of quality stuff out there. It would be very helpful if you could make a course on DJANGO REST FRAMEWORK. Need guidance in that part.
Thank you for everything you are doing for us and we also make sure that we will watch all the ads and visit the pages as a support to this channel.
Love for your dog from India.
I'm 13 years old this is a best courses out there
@@Ayasir-lo3ir I am 5 years old and i think you are right
@@2024comingforyou I came straight off my dad's telescope and I'm already being genetically coded to learn from Corey Django's series.
I'm still in the womb and this is the best course I have ever watched on django
No words to say beyond other viewer comments! Creating personal Operations Manual step by step for a foundation of future projects thanks to you!
Ready to complete this and dive into other topics by you...!
1:40 getting data from json in shell
4:45 Paginator
8:45 using Paginator with class based view (CBV)
11:30 adding pagination UI in templates
23:00 filtered data Paginator with class based view (CBV) get_queryset
25:05 get_object_or_404
Simply the best Django tutorial you'll ever see on the internet
You are love, Thank's for making Django easy for us, I will never able to complete my final year project(B.Sc) without your loving playlist of Django, it helped me a lot
Thanks for always showing the errors and how we can fix them. This is the best Django tutorial I have watched so far. :)
Thank you for this tutorial, Corey. You're an angel. Hope you're doing fine wherever you are right now.
I generally use Adblock but just for your videos I specifically disable Adblock.. really thank you very much. !!..
Thanks!
For anyone stuck with pagination, yeah, this changed in newer versions of django. with Django 3.0 i get pagination on the users-post page, but the not post page itself. As corey said, this part of the code is not DRY(repeated code in both html files regarding actual pagination) but still they behave differently.
I did the same and it worked. But I always follow documentation before writing code.
one of the best teachers on youtube
Thank you so much for being patient with us, even without seeing us.
32:55; No need to replace post with object, Doing this can induce an error.
btw Great Series, Great Work, Thanks a lot.
Hey, am getting anl template syntax error at line 24, time: 20:02.
Could not parse remainder '|' from 'page_obj.number|'.
Please help 🙏 🙏🙏🙏🙏🙏🙏🙏🙏
in the elif line make sure that the 'add' comes directly after | so it looks something like this '|add' this helped me
This is the best Heroku deployment tutorial ever!
Great tutorial, Corey! Amazing! Kudos!
Awesome job sir! usually i'm on c# but this really makes appetite
Thank you so much for this video!!!
I was stuck on this problem from a long time and was thinking to apply concept of Lazy Loading, but this solves my problem.
Thankyou!
i really felt bad when you are saying sorry, we are all learning because of you, so you can make as many as u want
At 22:00 in the end of paginations.
I did some changes on the pagination buttons I hope you like it:
{% if is_paginated %}
{% if page_obj.has_previous %}
First
Previous
{% else %}
First
Previous
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if page_obj.number == num %}
{{ num }}
{% elif not page_obj.has_previous %}
{% if num = page_obj.number|add:'-2' %}
{{ num }}
{% endif %}
{% elif num >= page_obj.number|add:'-1' and num
Hi Marcelo, this part is not right I'm afraid
{% else %}
First
Previous
{% endif %}
because it will be visible even if there isn't a previous page, which should not be the case.
same with this:
{% else %}
Next
Last
{% endif %}
it will appear even when there isn't a next page. Also, their href attributes are '#', meaning they will not change to a particular page
@@shemmuthanga6352 To be honest I don't know exactly what's going on in that piece of code, but anyway, here's what i meant with this code:
I wanted the buttons to appear even if there is no previous page before the first one and even if there is no later page after the last one.
And to avoid confusion I changed the colors by changing the class from "btn btn-outline-info mb-4" to "btn btn-outline-secondary mb-4". Try it in your django code see what you think :P
AMAZING AND CLEAR TUTORIALS WELL DONE COREY!!!
man you're just Amazing! Really your courses are better than those Udemy paid ones
The way this begins with importing JSON, is a neat touch. Django is amazing. Btw- Which beers improve your programming?
After overriding the save function in users/models.py I was unable to create new users. a fix to this was changing:
def save(self):
super().save()
to:
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Hope it helps somebody! Thank you for everything that you do Corey. Keep it up. Your tutorial has restored my motivation!
thanks alot
Thanks A lot
Found a solution
The save method update solved creation of Profile Problem but new error generates saying default.jpg doesn't exists in media folder even though it exists. Tried even restating the development server . problem still persists
i had the same issue
Thankyou so much ,i realized i wasn't able to create user after reading your comment :D
You don't know how many people appreciate your services
Me: Watching corey's video
Corey: I know that this is confusing especially when you're not actually doing it
Mr Corey Schafer Thank You for these awesome , informative tutorials
great video! And as others have mentioned, it's nice to see how you solve errors as well.
Loving the series. Thanks Corey!
To anyone getting an error when creating posts:
I have noticed there is a small error maybe due to changing of Django versions
When creating posts, providing author_id = post['user_id'] gives an error.
Just do a user = User.objects.get(id=post['user_id']) before making the post and instead of author_id, do author = user.
Of course you will need to import User model as explained in previous videos.
importing User model...
from django.contrib.auth.models import User
right?
but still shown error : User matching query does not exist.
@@alexkoshy1999 did u solve bro..i am still stuck in this problem
@@dihajnasah8077 no bro...i leaved it..and manually posted some gibberish post
@@alexkoshy1999 No bro no need to add gibberish post
its not good practice
this is how i identify my users id from shell , because at the first i have created some users and deleted for some resons thats why i has been facing this issue
here is the shell code which i have used
>>> user = User.objects.all()
>>> user
>>> user = user.first()
>>> user
>>> user.id
9
>>> user = User.objects.all()
>>> user
>>> user = User.objects.get(username='NewUser')
>>> user
>>> user.id
10
>>>
i hope this would help
I found this tutorial to be pretty helpful, thank you. I was wondering if you will do another part on many-to-many relationships for models particularly in relation to CRUD. Maybe for example for your blogs, you can have tags.
I have been watching Corey's videos more or less all day, but this is the first time he has made a misstate :D (34:00 --> )
Thank you 🙏 -this JSON thing is extremely helpful
Hi corey, this entier tutorial is incridible and understandable , but can you extend this series a bit and let us know how to implement chat feature so that users can chat as well after logging in
I was unable to to add he posts.json using the import json... I have a Mid 2010 macbook pro laptop for what it's worth. I'd like to add those addiional profiles if possible.
Corey, if you could bottle this and sell it... but then, you're probably already rich from working as a programmer. It would be pretty cool if you could find someone who knows as much as you do--but about other computer topics, then teach them how to plan a recording session. You could sell it as a documentation service to companies with products like Django and Git. Anthony Sherrill says you don't edit your mistakes out, but the vast majority of them appear to be planned mistakes--not mistakes at all. I was using another set of tutorials, but that guy wasted oodles of time just chit chatting. I love the way you plan, follow your plan, and get to the next point.
I perform a lot of edits on my videos. I'll leave mistakes in if I feel like they have some value to the viewer, but if they are mistakes that won't give any value then I try to edit them out.
2 and a half hours later to finally get it working and my head is about to burst! haha
Mr. Schafer! You are a boss!!!!
That is all :)
Once again, a great video of yours. Congrats!
35:35 "You won't believe these clickbait titles!" -- thought that was pretty funny.
@4:08 well, could you please please show how to add images to posts, I was thinking about django-ckeditor, or maybe just a simple form one image per post plus thumbnail in the listview on home.html along with search section would spice up the blog even further. Thank you for this tutorial, it's great!
I need this as well
i couldn't understand 18:10 , how can num be greater than page_obj.number and less than it, in the same time ?? pleaze clarify this to me :)
To any of you who get an error of django.db.utils.IntegrityError: FOREIGN KEY constraint failed.
That can be happening for some reasons (most of them are detailed in the comments), but I didn't see any comment addressing the problem I had.
Because I played with the creation of the user a little bit, my user_ids weren't 1, 2, and 3.
However, the JSON file contains user_id of 1, 2, and 3, so I basically tried to upload a post to an unexisting user.
To check the user_id of each user you can do the following:
from django.contrib.auth.models import User
users = User.objects.all()
for user in users:
print(user.id)
After that, you need to update the user_id in the JSON file to one of the numbers you have.
Hope it helps!
THANK you!
thanks
Hello? How would i go about inserting new posts using the shell in windows? Mine is showing that it's running perfectly but no post is added
Hi Corey,
Thank you for this great tutorial. I have learned a lot.
after loading the JSON file and saving every post in it I am getting a django.db.utils.IntegrityError: FOREIGN KEY constraint failed Error
please help me with this issue
same error
+1
having error because of user_id value.. in database user_id for each user doesn't restore if you delete a user from database. I mean if you delete a user whose user_id was 2, if you create new user, then index 2 will not be assigned to any user, it will remain null and new_user id will be 3.
As pointed out: Whenever you delete and create a new user, primary key (pk) and user id (id) will continue and not be reset. Therefore, if you followed the tutorial, chances are high you don't have users with id 2 anymore. Hence, in posts.json you need to replace id 2 with a corresponding value. To find good id values you need to query the db.
First, open a shell:
python manage.py shell
Second, in the Python shell run these commands to find all ids of all users:
from django.contrib.auth.models import User
users = User.objects.all()
for user in users:
print(user.id)
Third, in posts.json replace the ids with valid ids from your db.
@@mahaheruka4966 Thank you for this .... you provided the solution for me...
Great lecture!! I experienced some error following along of the video, please refer to the code above if you experience error as well
At 28:40, remember to add the forward slash in the end of the string. I did not and ran in to some 404-issues for certain users (not all).
How do I know I can use 'author_id' for the models.Post at 2:54 ? Unfortunately I didn't find anything about this term in the docs. But it seems like everyone uses it. How do I know which kind of keywords (like 'author_id' in this case or 'paginate_by' at 8:53 or 'page_obj' at 12:30) I can use? Btw. 'author.id' would seem more logically for me.
smashed the liked like hulk and subscribed, excellent tutorial my friend many thanks! regards from Peru!
I love that series, actually I've learned most of my Django skills here;)
Is there a chance that you'll make one on cookies handling/ session storing?
I would like to inform you guys, instead of using get_query_set function, it should be get_queryset function (only one underscore '_') to successfully filter out the username in counting the number of post and display its posts. I don't know if it has something to do with the django versioning but, if you were using get_query_set function, it will not work. Sir Corey, please double check this. Thankss! Anyone correct if i'm wrong - 24:39
You’re right. I fixed it at the 34:00 minute mark
Thanks for that because without the fix it was returning all posts.
I would pay around 20$ for an advanced django tutorial from Corey Schafer and I NEVER PAY for coding material.
I have question if anyone can answer, how to get familiar with all these methods. We can't remember all these methods right? Where to check for them if we forgot ? Great Series Corey. I am learning more from you than my university lecturers. And thank you!! AS Soon AS I will get my first job, I am gonna contribute to your channel through patreon.
*Corey:* Apologizes for making two small mistakes.
*Me who makes 10000+ typos even after watching his videos:* um....i-it's totally okay mate...
Thank you for these wonderful videos!
Love these tutorials man
I have a problem with posts ordered by author. Like in your video in 33:15 to 33:45 I get all posts(12) even after small changes in views.py like getqueryset. I noticed that when I click on the user id it getting user id from Url but the first posts that I see are mine and then I see the users posts no matter which user I chose(they are always sorted by Me>NewUser>NewUser2>NewUser3). I also didn't use JSON file with posts but make them through the page and maybe it cause some problems(also sorry for my bad English xd).
Ok, I'm just stupid and blind xd. I had getqueryset instead of get_queryset.
thanks corey.. you are the pure sole.. Someday I am really going to meet you.
14:10
When accessing an attribute in the page object to make a button for a previous page, we use page_obj.previous_page_number
Isn't this a method? Why don't we give it () page_obj.previous_page_number()
Corey Schafer
made 2 mistakes in one video. It is 8th wonder to me. really, It is more rare than human goes to the moon. I'm really impressed.
Corey, you are good.
20:16 TemplateSyntaxError at /
add requires 2 arguments, 1 provided. i could not able to resolve issue please help.
did you solve it? same problem mee too. {% if page_obj.number==num %} show this column error
Hey, I am getting this same error, did you solve it ?
I was missing a quotation mark around the '-3' and '3' in ``` page_obj.number|add:'-3' ```
Thank you Corey!
Thanks for this tutorial, I really enjoy the way you teach.
But I have a problem with the if elif statement in home.html: throws this error :"TemplateSyntaxError at /
Invalid block tag on line 32: 'elif', expected 'empty' or 'endfor'. Did you forget to register or load this tag?"
I've bee through my code several times, even erased that part and started all over again, checked all my templates, but not working...
any idea? thanks
hey did you find a workaround/solution for this?
Did you find the solution? Anyone?
That small heart attack you get when you test something and it doesn't work because you swear you followed the instructions but then it turns out Corey made the same mistake and it's fixed 2 minutes later.
Thanks a lot for your lessons!
The registration and profile create worked fine during Part 8 as we were building the code. Now in Part 11, I tried to register a new user, and it failed. Seems Django does not like form.save() in the register "view.save() got an unexpected keyword argument 'force_insert". Not sure if the class based views did something. I user is created but then you also get a "user has not profile error". The user is added to the admin, and you can create a profile in the admin manually. Thoughts ???????
I noticed, that if you are doing this in command prompt for windows users, @ 2:25 you need to tab twice!
Also, I noticed if you make errors as typing this, even fixed it wont work, you have to start over from command prompt and start from import json
if anyone is following this tutorial at the date of this comment and having trouble with the json file, you can:
from django.contrib.auth.models import User
and then modify the query a bit
i did
for p in posts_json:
post = Post(title=p['title'], content=p['content'], author=User.objects.get(pk=p['user_id']))
post.save()
django expects a user object instead of just the primary key, at least in django 4.2.1 which is what I'm using.
Thank you, sir 🎩
Thank you!! this fixed my issue
34:29
Sorry guys, I usually don't make these many mistakes.
Just wow.
We want E-Commerce Tutorial :)
I'm getting: TemplateSyntaxError at /
Invalid block tag on line 32: 'elif', expected 'empty' or 'endfor'. Did you forget to register or load this tag? on line 11:
{% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
Not sure how to fix this. I try copying directly from your files on github but still getting this issue.
did u find the solution bro?
Any solutions on this??!!
Hello Corey ! Thank you for this Nice Tutorial. But i Can not Understand "view.kwargs.username " the Line 3 of blog/user_posts.html . where the view comes form? Can you explain it plz.. ?
same here. I can archive wanted results by using function based view and just grabbing id from url
Hey Corey, maybe in the next tutorial you can show us how to use django-cities feature for the registration form?
awesome tutorial!
Hi corey, i am getting TypeError: 'dict' object is not callable error while calling the saving function.
Can you please help?
for pagination when i created another user, the profile of the new user is not being created instead an error message is thrown which says - save() got an unexpected keyword argument 'force_insert
There is an issue with the code in this video that I fixed in the later videos. If you're getting an error that says something like "save() got an unexpected keyword argument 'force_insert'" then please update the save method in users/models.py to the following:
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
I would love to see you do a flask api tutorial
Corey, could you elaborate on the variable {{ views.kwargs.username }} in the user_post.html file? What is 'views.kwargs' part ?
views.kwargs means :
kwargs stands for keyword arguments.
It is a lookups on dictionary in template.
Referring to the function get_queryset inside
{view.py .... username=self.kwargs.get('username'} file.
Basically, it is asking the function get_queryset from view.py file to pass the username as an argument to it.
view.kwargs.username
Please Corey correct me if i'm wrong?
Shouldn't it be views.py rather than view.py? @@Canda-fh4xc
The answer probably is this: stackoverflow.com/questions/45098826/access-kwargs-from-a-url-in-a-django-template
@@fangle0121 This link was helpful
you are the BEST of the BEST. thank youuuuuu:))
when adding posts in the shell, how did we have author_id? Did django create this when we did a ForeignKey field? Could I use author.id instead?
Yes, i have same question, can somebody here help?
Foreign keys are converted to _id by django ORM:
root@root SocialApp % python3 manage.py sqlmigrate blog 0001
BEGIN;
--
-- Create model Post
--
CREATE TABLE "blog_post" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(100) NOT NULL, "contect" text NOT NULL, "date_posted" datetime NOT NULL, "author_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE INDEX "blog_post_author_id_dd7a8485" ON "blog_post" ("author_id");
COMMIT;