Also the line: from netflix.models import Movie is a module importation. It's more a python stuff here. We have a class called Movie inside the file models.
Remember that to be able to use a function or class that is not available in a given file, you should import that function or class from it source inside the file that should use it.
Let take a simple exemple, guess you have this architechure:
- root
|--- file1.py
|--- file2.py
And file1.py contains this:
# inside file1.py
defutil_function(value):"""Here is an utils function."""print(value)# Do usefull stuff with the value...
classUtilClass:"""Here is a util class."""def__init__(self,name):pass
and then you want to use the util_function of the UtilClass inside file2.py,
you can import them like this:
# inside file2.py
from.file1importutil_function,UtilClass# we can use them
util_function(56)utlil_class=UtilClass()
I fyou got that, you should also know that, as we need to import a class or function or module in order to use it in another file, we should import them into django shell too. That why we need to import Movie model if we want to test it into django shell. And becasue the django shell root folder is the project root folder django_netflix_clone, which contains all our app folders modules (netflix included), and also because Movie is inside the path django_netflix_clone/netflix/models.py to import it we do from netflix/models import Movie.
Hope that help you.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Also the line:
from netflix.models import Movieis a module importation. It's more a python stuff here. We have a class calledMovieinside the filemodels.Remember that to be able to use a function or class that is not available in a given file, you should import that function or class from it source inside the file that should use it.
Let take a simple exemple, guess you have this architechure:
And
file1.pycontains this:and then you want to use the util_function of the UtilClass inside
file2.py,you can import them like this:
I fyou got that, you should also know that, as we need to import a class or function or module in order to use it in another file, we should import them into django shell too. That why we need to import
Moviemodel if we want to test it into django shell. And becasue the django shell root folder is the project root folderdjango_netflix_clone, which contains all our app folders modules (netflixincluded), and also becauseMovieis inside the pathdjango_netflix_clone/netflix/models.pyto import it we dofrom netflix/models import Movie.Hope that help you.