what does " models.Model "mean
Question:
I’m working through https://docs.djangoproject.com/en/1.4/intro/tutorial01/ .
They include the following :
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
what does ” models.Model “mean?
Answers:
It means: make the Poll
class inherit from the Model
base class from the models
module.
It’s the class that you are sub-classing to create your model.
Do you know what inheritance is? I would start by looking at some examples:
http://parand.com/say/index.php/2009/04/20/python-simple-inheritance-example/
It is basically saying to use all the properties that the Model class has plus whatever you define on your class.
Good luck
in php that would be:
class Poll extends Model
{
var $question;
var $pub_date;
}
Model is a class that is in the models module in Django framework…
For answer this question you need to know the meaning of module, package and class in python.
In summary a module is basically a collection of related code stored in a file with a .py
extension. You can define functions, classes or variables in a module.
To use the module in the main program, follow the code below:
import My_Module
When developing a large application, you may encounter various modules that are difficult to manage. In this case, you will benefit from grouping and organizing your modules. That’s when packages come into play.
This image is a example for package in python:
To be considered a package, a directory must contain a file named init.py .
We can import specific modules from this package using the dot symbol. For example, we can use this code to import the dataset module from the above package:
from my_model.training import dataset
With these definitions, you now understand models is one of the Django modules which includes functions and classes And the Model is a class that models use it for working with database, and your poll class inherited from each other .
I’m working through https://docs.djangoproject.com/en/1.4/intro/tutorial01/ .
They include the following :
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
what does ” models.Model “mean?
It means: make the Poll
class inherit from the Model
base class from the models
module.
It’s the class that you are sub-classing to create your model.
Do you know what inheritance is? I would start by looking at some examples:
http://parand.com/say/index.php/2009/04/20/python-simple-inheritance-example/
It is basically saying to use all the properties that the Model class has plus whatever you define on your class.
Good luck
in php that would be:
class Poll extends Model
{
var $question;
var $pub_date;
}
Model is a class that is in the models module in Django framework…
For answer this question you need to know the meaning of module, package and class in python.
In summary a module is basically a collection of related code stored in a file with a .py
extension. You can define functions, classes or variables in a module.
To use the module in the main program, follow the code below:
import My_Module
When developing a large application, you may encounter various modules that are difficult to manage. In this case, you will benefit from grouping and organizing your modules. That’s when packages come into play.
This image is a example for package in python:
To be considered a package, a directory must contain a file named init.py .
We can import specific modules from this package using the dot symbol. For example, we can use this code to import the dataset module from the above package:
from my_model.training import dataset
With these definitions, you now understand models is one of the Django modules which includes functions and classes And the Model is a class that models use it for working with database, and your poll class inherited from each other .