For anyone who wants to know how to get the foreign key related instances, you have to use model_name_set.all function in your template. For example, a blog post has many comments, so when you try to get the comments through the post, you need to use "{% for comment in post.comment_set.all %}" in your template. If you do not understand what I am saying, go to the site: developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Generic_views This is the most useful and detailed tutorial I have seen so far! Good job!
@corrichyou8 жыл бұрын
Well done imitation of designer :) 8:40 - 8:50
@ethansun32518 жыл бұрын
I reflectively hit Ctrl-z on keyboard after you delete all the original views...
@khushalimal51863 жыл бұрын
Never everrrr have I seen a clearer explanation of Generic views than this oneeee✨
@Loeil226 жыл бұрын
Simply the best programming channel on YT
@superuseriii8 жыл бұрын
Great tutorials man. Keep up the good work but here's a side note. For the IndexView the code is simple enough to just use the default implementation. So instead of overriding get_queryset all you have to do is override the model attribute to use the model you want. INSTEAD OF: class IndexView(generic.ListView): template_name = 'template.html' def get_queryset(self): return Album.objects.all() YOU CAN JUST DO: class IndexView(generic.ListView): model = Album template_name = 'template.html' And that's it!!! ALSO(from the Django docs): " If context_object_name is not set, the context name will be constructed from the model_name of the model that the queryset is composed from. For example, the model Article would have context object named 'article'."
@amalik42736 ай бұрын
Thanks. Didn't know about the context_object_name part.
@TrustEngineers7 жыл бұрын
Love Django, love Buckey, you're the man, best Django tutorial on the net!
@345angad8 жыл бұрын
Is it weird that I still think Django is confusing by the time 29 tuts have passed?
@byYuriy8 жыл бұрын
+Mr_Teacher _Man It is complex at the start but it is awesome when you will get it.
@345angad8 жыл бұрын
+Yuriy Reshetylo I''ll just continue watching Bucky's tutorials. Hopefull I''l understand it after a certain amount of time.
@ofir-bar-softr8 жыл бұрын
+Mr_Teacher _Man i know your feeling, don't give up! :) suddenly it became much more clear to me
@Darthdeedee918 жыл бұрын
don't follow the tuts blindly or you will just be entering what he enters in. try to customize it to your own so you are learning as you go. you might run into some problems but fixing the problems and learning from them is what really makes you understand the workings of Django (probably anything for that matter).
@Hackaprende7 жыл бұрын
Everytime I learn something, I think "But what if this or that?" and I try it, in that way I learn more, for example, "What if instead of passing just context_object_name = 'album_list'" you want to pass multiple objects to the template like before when we had a dictionary, I´ll try to learn this even if it´s not part of the tutorial (at least so far)
@MatthewDickensmjd8 жыл бұрын
Those Darn Web Designers! Lol I laughed so much at that.
@InsaneBastardGuy8 жыл бұрын
I like your impression of a web designer.
@GelsYT4 жыл бұрын
NoReverseMatch at /music/1/ Reverse for 'favorite' not found. 'favorite' is not a valid view function or pattern name.
@eeeyrie3 жыл бұрын
I know this is old, but just remove the stuff for favouriting like he did.
@MichaelAbebreseAgyeman8 жыл бұрын
model = Album is the same thing as query_set = Album.objects.all and it's the shortcut way of def get_queryset()
@muntadarmuhammad45786 жыл бұрын
i think this is kind of not logical especially DetailView how can URL know the pk = album.id
@AlbertStepanyan8 жыл бұрын
thanks for tutorials .. quik question.....what if out detail view depends on many models not just one???
@21timster6 жыл бұрын
following!
@iamzumie4 жыл бұрын
Finally I understand generic views! :)
@tonyiguru75954 жыл бұрын
Anyone getting this error: 'as_view() takes 1 positional argument but 2 were given' was caused from omitting the parentheses in the urls.py details as_view.... It should look like this, if you use re_path. re_path(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'),
@Tano05 жыл бұрын
im having a rough time validating a form that has a "fk" of a class i have already created using a createclassview class. Any tutorial on that matter?
@PavolSojak8 жыл бұрын
hey man! thanks for all these.. I really enjoy these trainings, and learned a lot over the last 2 weeks following your tutorials ;)
@wesleysartori40795 жыл бұрын
Thank you, I was missing out on some points and your video took away my doubt.
@Jigyasu_RP6 жыл бұрын
Hello everyone..Please can anyone help me out... When I use object_list I am getting error.. As NoReverseMatch Reverse for detail with arguments'(",)' not found. 1 pattern (s) tried : ['music/(?P[0-9]+)/$]
@terangaplus6 жыл бұрын
Hey ! (5:13) - in vews, class IndexViews, how can we repesent Album and Song models in the same class ? I tried to do : def get_queryset(self): return Album.objects.all() def get_queryset(self): return Song.objects.all() But it doesn't work Please, help !
@Ishanatmuz8 жыл бұрын
You said that pk and id are interchangeable and we can use either one. I tried to use id instead of pk in the urlpatterns, but it didn't work. When I use pk it works but it didn't work with id. Why is that?
@waseemikram28508 жыл бұрын
as_view() takes 1 positional argument but 2 were given found this error can you help me?
@waseemikram28508 жыл бұрын
TypeError at /music/1/ as_view() takes 1 positional argument but 2 were given
@Ishanatmuz8 жыл бұрын
I am assuming you have the problem with DetailView. Since I don't have your code I can't tell you what's wrong. Here is my code for your reference. music/urls.py # /music// url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'), music/views.py class DetailView(generic.DetailView): model = Album template_name = 'music/detail.html' If this doesn't help you then you will have to provide your code to check.
@ivangrobenski53898 жыл бұрын
just use "pk" instead of "id" keyword... Turns out it actually matters which one u use...
@looploop66124 жыл бұрын
I have 3-week experience in Django but still get confused by its relationship among files and variables
@ishwaraju8 жыл бұрын
Reverse for 'favorite' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] ... i m facing this error .. please help
@steffikunc79488 жыл бұрын
had the same problem, look at detail.html and compare to his detail.html at 2:10 made my page work now
@kedarkhandi7 жыл бұрын
what you did to resolve it ?
@kazishamsilarefine7 жыл бұрын
Have you deleted your old code? If you comment out all it will not work :D
@ant715557 жыл бұрын
Thank you very much
@concerned19017 жыл бұрын
Thanks, It really helped, but can you tell why it behaves that way???????
@runthomas6 жыл бұрын
very good presentation, you cleared up a troublesome subject for me...thanks
@kojakeugenio10647 жыл бұрын
This doesnt work for me. I am getting this error when i click any of the album NoReverseMatch at /music/3/ Reverse for 'favorite' not found. 'favorite' is not a valid view function or pattern name.
@tonymugendi85237 жыл бұрын
did you delete the favourite function?
@Dadusingh10107 жыл бұрын
yes ( i am also getting same error)
@Dadusingh10107 жыл бұрын
hey ..It solved i was forgot to clean detail
@Dadusingh10107 жыл бұрын
might be you too
@chrisk93037 жыл бұрын
change that -from django.core.urlresolvers import reverse- to that -from django.urls import reverse-
@alienaerobics1947 жыл бұрын
I'm not sure why this worked for Bucky without adding a context_object_name = album to the DetailView class. I'm not following his music/albums format, but mine is similar and I had to add the context object name to show a valid details page.
@shivajohari22497 жыл бұрын
I also got sae issue ... your comment saved me .... Billion Thanks :) even I wonder how his code was working fine ??? :/
@chrisk93037 жыл бұрын
if you want to import reverse, import it from django.urls from django.urls import reverse
@balasubramanyamavvaru13117 жыл бұрын
Thank you very much Mr Bucky. Very Nice videos. I am the Beginner for Python and DJango. Very nice explanation in all the videos. 29th video is more confusing. The pattern for the LIST VIEW is completely changed from Video-28 to Video-29. How did you get this change ? Please explain. We will be very much thankful to you. Any advanced DJango online courses you r offering? what is the cost ?
@victorkironde54257 жыл бұрын
Thanks, Bucky. How do you go about learning quickly and efficiently?
@couturexolivia6 жыл бұрын
Amazing video thank you I've been looking forever for this!!
@koualsky6 жыл бұрын
i still don't get the generic views... i understand how it works but i don't know why is better than simply get object and render() it...
@tanu38735 жыл бұрын
Its just a little less code to type
@marpich233 жыл бұрын
Loved this video , thanks for your clear explanation
@faustinutub6 жыл бұрын
i didn't notice that bucky removed if all_albums condition and debugged django's work a little. when you give another name to object_list it doesn't disappear from code and you still can use it as well as new given name. just for your information.
@jamesmasonic4 жыл бұрын
still dont get it. i watched every single one in youtube. i dont get it. please someone make a dummies version of this nightmare..
@Babe_Chinwendum4 жыл бұрын
How about now?
@winuxworx6 жыл бұрын
The biggest challenge to me in following this old tutorial today Dec, 2018. I'm having issues with "urlpatterns" and now the requirement to use "pk" or "slug" which wasn't required here. or maybe i'm just doing something wrong. Either way this tutorial is very good.
@Crucizer5 жыл бұрын
I'm having the same problem, help me!
@dinkarinjosh6 жыл бұрын
what if i need to send an error or warning message to html page? earlier we used dictionary for the saem.. {'album': all_albums , 'error_message' : 'no album found'} ?
@swells5ca5 жыл бұрын
how do you add songs, I have the SongCreate modelform made - added song_add to my urls and have tried everything I can think of in song_form.html? I am sure it is simple but I can't see it help?
@parasmalhotra76336 жыл бұрын
I felt the generic views as simple rather than the earlier complex design.....😅 Thanks bucky your Tutorials are amazing
@udaynaiksn6 жыл бұрын
Hi Bucky, How did you add a custom icon on title bar. I tried to add in base.html file and its not working. :( when opening the base.html it shows but not through Django server page
@Zelanias7 жыл бұрын
What does view:detail mean in the url-link of index.html? In which video is it? I don't have much time and that is why i am asking. Cheers.
@sanjoyghosh63817 жыл бұрын
after making this changes it show me No Album.....Why??? pls help
@sam4077kr7 жыл бұрын
If you used {% if all_albums %} in index.html , replace it with {% if object_list %}
@abcd-ek1rt6 жыл бұрын
+Aqib Zaheer, Did u fix it? I am also having the same problem
@RamisaAnjum6 жыл бұрын
I had the same error and after I made the changes in the index.html file, it was fixed. the if-else block should be removed.
@StuartP976 жыл бұрын
@@sam4077kr You saved me, cheers!
@arifshariar52904 жыл бұрын
@@sam4077kr YOU SAVED MEEEEEEEEEEEEEEEEEEEEEEE!!!!!!!!!!!!!!! thanks thanks thanks
@AbhishekNigam7 жыл бұрын
Git's really helpful, when bucky's doing some big changes, you can save a snapshot of that code by commiting.
@kabirkanha4 жыл бұрын
Or you could just comment it out, otherwise the next commit will overwrite it.
@test17297 жыл бұрын
Thanks for an excellent set of tutorials!
@taihatranduc86135 жыл бұрын
Are pk and id really interchangeable? I tried to use id instead of pk in the urlpatterns, but it didn't work. When I use pk it works but it didn't work with id. Why is that? please help me
@GelsYT4 жыл бұрын
django.urls.exceptions.NoReverseMatch: Reverse for 'favorite' not found. 'favorite' is not a valid view function or pattern name. [10/Apr/2020 14:58:23] "GET /music/1/ HTTP/1.1" 500 159601
@romit58674 жыл бұрын
in your detail.html page change that favorite to details
@emmetgingles20737 жыл бұрын
Strange. In my code all_album returns the list of albums but object_list doesn't. I didn't have to set context_object_name.
@Rajatgng6 жыл бұрын
why there is no return in DetailView class as same as in IndexView??
@黃書豪4 жыл бұрын
so where the favorite function go?
@addohm8 жыл бұрын
Would you do a more in depth tutorial on CBVs? I'd be really interested in heavily customized form control.
@alirezaghodsipoor22396 жыл бұрын
Thanks for perfect teaching Bucky! How does django recognize where to place "Album" model, declared in DetailView, in template 'music/detail.html'?
@inhaledeath38996 жыл бұрын
At 8:16 he explains that the queryset is automatically stored in the variable object_list for use in the html-files
@alirezaghodsipoor22396 жыл бұрын
Inhale Death: I think object_list is used only for ListView. My question was related to DetailView.
@deepakofall46774 жыл бұрын
Thus is just what i wanted, thanks a lot
@yoco80417 жыл бұрын
I had an issue while wanting to display a detail of an object from DB. Instead of object_list put simply object and that is it. It will be displayed.
@ggodoyoliveira8 жыл бұрын
That is beautiful, thanks for showing to us!
@hrishigg30247 жыл бұрын
Its not displaying any logo for my album. What should I do?
@Jordan-lz6hd3 жыл бұрын
I struggled to get a detail view. The cause of the blank detail view page was the wrong object name used in the for loop in detail.html. Mine said refer.song_set.all which was pointing to an object that was no longer an instance of the class Album because the DetailView function set model = Album. This is the new instance of the class Album. So change your for loop in detail.html to {% for song in album.song_set.all%} and that should fix it.
@harryammon22748 жыл бұрын
Whilst its all good having a more compact code, alot of the code that got deleted from views.py was error checking incase no records were found in the database, unless Bucky goes on to add this in a later the tutorial i do not see the benefit of this if it means there is no error checking included
@BLOBBERNATOR8 жыл бұрын
I thought this was the case too, but I tested out the same things we did a while back and all of what we already did with view functions is handled. Its almost like magic!
@user472637 жыл бұрын
Hi Bucky, Please show us how to add songs, its hard for me to do it since it has a foreign key.
@Vijay-dw5ej3 жыл бұрын
Thanks dude, great explanation and helped lot. Thanks a lott
@chandrabhushankesavabhotla85007 жыл бұрын
detail.html doesn't have Form code in video 29 which was there in 28
@tanayshirodkar6844 жыл бұрын
AttributeError: module 'music.views' has no attribute 'detail'
@collenserudzai71674 жыл бұрын
Hey nice nav bar,, how can I get something like that,, refer me to a tutorial where this was made please
@maqboolthoufeeqt6 жыл бұрын
When I click on any of albums it shows like NoReverseMatch at /2/ Reverse for 'favorite' not found. 'favorite' is not a valid view function or pattern name. why this error comes?
@shrutibansal46077 жыл бұрын
Why didnt you make a video for creating songs using foreign key?
@concerned19017 жыл бұрын
Hey bucky how can I add an icon with the title of the page????
@kabirkanha4 жыл бұрын
Look up favicons and how to use them
@andromeda7zw7 жыл бұрын
I can see all the albums but for some reason the details page remains blank even after object_list explanation. Anyone with a similar issue?
@mildredjessicanwonye60527 жыл бұрын
I'm also having the same issue
@darthrinvador7 жыл бұрын
same for me
@tommyalfarabi48967 жыл бұрын
just review your codes, Bucky has some changes in detail.html
@bikis98647 жыл бұрын
Tommy Alfarabi yup..i overlooked it thinking it was just bootstrap styling. Thanks!
@akshayjagtap38897 жыл бұрын
u'music' is not registered namespace can anyone help me with this
@vitalyorlov91547 жыл бұрын
Thank you for the lesson! very informative
@inhaledeath38996 жыл бұрын
I used comments to explain the optional renaming of object_list in my views.py right under "template_name". Funny thing: Then it generates an error message. If I delete the comment, everything works. Does anyone have an explanation for that?
@mimounimohamedali75947 жыл бұрын
oh my god ! what are you doing !!
@cahilldes6 жыл бұрын
Im following along using Django 2 , and the object list doesnt work so use the all_albums with the context if anyone else is having issues with that too
@kaviyaravi72635 жыл бұрын
I'm facing the same. Have you found the solution?
@runthomas6 жыл бұрын
mixins are still impossible for me to grasp though in class based views
@waqqas_the_wicked8 жыл бұрын
Django makes me want to make a cool and useful website but i never have any ideas :/
@flvyu8 жыл бұрын
thats your first problem, help me build mine. Give me your email, and ill email you.
@isacsamil8 жыл бұрын
@Flavio if you are looking for volunteers am in.
@akagilnc58368 жыл бұрын
akagilnc@gmail.com
@flvyu8 жыл бұрын
Ningchuan Li I dont think I want to get a partner right now for this cause I am linda busy. Sorry guys
@akagilnc58368 жыл бұрын
+Flavio Andrade never mind.
@rashmitpankhania65137 жыл бұрын
QuerySet' object has no attribute '_default_manager' help me
@rashmitpankhania65137 жыл бұрын
Generic detail view DetailsView must be called with either an object pk or a slug.
@ahsanhabib25778 жыл бұрын
how come the detail view know that the object name is 'album' in detail.html ?? is it the lower case of the "model" name mentioned in DetailView class ???
@kgehmlich8 жыл бұрын
Django automatically chooses an appropriate context variable name based on the model name ('Album' in this case, which is converted to the lowercase 'album' when being passed to the template). See here for more details, about 3/4 of the way down: docs.djangoproject.com/en/1.10/intro/tutorial04/
@exis86 жыл бұрын
now i figures how bucky can do so much coding without making mistakes or stutter. now you probably just gonna say 'nah i think you are just bad', It appears that the recorded window is slightly smaller than the desktop size, which is abnormal. I think he have the readied script outside of the recording area, and code according to the precoded code :) nice trick haha
@yeeteshpulstya98906 жыл бұрын
Exis Zhang everyone does that. That other code is reference code, which he didn't blindly copy. It takes effort and understanding.
@MohamedAyman-li6rp7 жыл бұрын
Thank you, Bucky.
@runthomas6 жыл бұрын
yes btu he didnt mention updating objects and deleting objects ...he only told part a story
@nepalitechguy80227 жыл бұрын
i have problems with my details.html
@arminoldboy9987 жыл бұрын
thank u Bucky.very useful
@consumerdude6 жыл бұрын
Django tutorial 29 Generic Views apps used in this tutorial \music\templates\music\index.html \music\templates\music\detail.html \music\urls .py \music\views .py
@GelsYT4 жыл бұрын
i did not delete i commented out all of them, they mean a lot to me :(
@akshat5288 жыл бұрын
I am using similar code but i am not getting albums view . Here's my code : view.py from django.views import generic from models import Album class IndexView(generic.ListView): template_name = "music/index.html" def get_queryset(self): return Album.objects.all() class DetailView(generic.DetailView): model = Album template_name = "music/detail.html"
@yanggao89988 жыл бұрын
i am getting albums view , but not DetailView ....
@yanggao89988 жыл бұрын
i am wondering what happened using generic . passing the id of album , the def function how to deal with querying in all albums . i can't figure the code model = Album out ?
@yanggao89988 жыл бұрын
i have fixed my problem , any code runs ok now . 'cause generic.DateDetailView i wrote , it should be generic.DetailView. my bad .
@03anish038 жыл бұрын
Use "from .models import Album" you are missing the dot there. Hope it helps.
@kojakeugenio10647 жыл бұрын
Why on the git these class didnt appear? github.com/buckyroberts/Viberr/blob/master/music/views.py
@priyanshgupta94746 жыл бұрын
everything will be correct ,we just have to remove/delete this part {% csrf_token %} {% for song in album.song_set.all %} {{ song.song_title}} {% if song.is_favorite %} {% endif %} {% endfor %} from detail.html file
@Seawolf1596 жыл бұрын
Great tutorial, but only if i wanted to make exactly what you're showing. Can't make after hours what i want to make. People should write documentation to be readable by people that don't actually already know wtf something is...
@RpMRickyMunoz6 жыл бұрын
2:40 i will still love u no matter what u do.
@0alejandromontes03 жыл бұрын
Oh god! I lost a lot of time going back and forth. Man, why didn't you start with Generic Views since the beginning?. It is like if you were doing OOP and moving everything again to Functional Programming. I feel so frustrated. LOL
@boxicool6 жыл бұрын
I love Django. If you have any project I can make it for you. I am freelancer, cheap cause I am leaving in Central Europe.