Note: the .create() method calls .save() automatically so there is no need to call it explicitly afterwards.
@Skaxarrat6 жыл бұрын
When we should use ModelName.objects.get(id=id) and when get_object_or_404(ModelName, id=id)? What are the differences?
@thedumbfounds7676 жыл бұрын
ModelName.objects.get(id=id) alone is problematic because it will give you an error if the model with that id doesn't exist, which is why it should be wrapped in a try-except block. get_object_or_404 is a helper function that automatically takes care of returning a 404 error if the model with that id doesn't exist. However, you should use get_object_or_404 only in views. Btw: the get_object_or_404 function uses ModelName.objects.get(id=id) under the hood with a try-except block. Here is the code for more information: github.com/django/django/blob/master/django/shortcuts.py. Any more questions?
@topiaamr6 жыл бұрын
AWESOME !! Thank you for the tut
@thedumbfounds7676 жыл бұрын
you're welcome, Topia!
@gmoneep6 жыл бұрын
how to use django 2 with react - GrapgQL - apollo . i think all videos in this topic is old !! would you make a tut in that ??!
@thedumbfounds7676 жыл бұрын
I'll perhaps show how to integrate frontend frameworks with APIs in the future. But essentially, because you expose endpoints (with GraphQL it's only 1), it can be consumed from any frontend, including react.
@Thesrik236 жыл бұрын
Nice work!
@thedumbfounds7676 жыл бұрын
thanks dude, after one more video we'll get into more intermediate/advanced topics! :)
@Thesrik236 жыл бұрын
The Dumbfounds You are doing an amazing work mate. Keep it up!
@thedumbfounds7676 жыл бұрын
thank you Srikant!
@azadabdullahshaheed5 жыл бұрын
For beginner tutorial using views is better than python shell.
@thedumbfounds7675 жыл бұрын
Thanks for the feedback. Thought it might be good not to mix the two when explaining how to deal with models.