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?

Asked By: user1592380

||

Answers:

It means: make the Poll class inherit from the Model base class from the models module.

Answered By: tom

It’s the class that you are sub-classing to create your model.

Answered By: Lim H.

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…

Answered By: mimoralea

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:

enter image description here

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 .

Answered By: Masoud Shakarami
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.