Thanks you 2 for your answers.
I think I've understood now. Again I apologize for the newby Python
question but I've read three times "Dive in Python" and it hasn't made
me thnigs clear. That's the reason why I've posted.
I thought there was a hierarchy like this models.Model.CharField ....
That's the reason why I didn't understood.
Daniel, you said, that a method can be imported, this mean that an
external method (method from a class like Model) can't be used
directly in the Person class for example ?
If I understand well, in "first_name =
models.CharField(max_length=30)", first_name is an instance of class
CharField. This instance send "30" to the "max_length" parameter of
class CharField. This parameter is used by an internal method of class
CharFiled. Is that right ? :-)
Thanks again to all
Regards
Alain
hello again, sorry for eventually annoying. But later in the Django
tutorial,
there is this code:
from django.conf.urls import patterns, include, url
.....................................
urlpatterns = patterns('',
(r'^polls/$', 'polls.views.index'),
......................)),
)
What I understand here is that "patterns", "include" and "url" modules
are imported.
After the result of the function "patterns" is assigned to
"urlpatterns". AS Daniel said that a function can't be imported, this
means that a method can be called (but not imported) or this means
that a function and a method are not the same thing ?
Regards
Alain
Hello Danielthanks for your answer and sorry for my english. As you said, it could be a problem of translation !!! :-)I really appreciate your help, I'm doing lots of progress in my python object programming curve ...OK, then to be sure how Python works ... let see this code:1 from django.db import models
2
3 class Person(models.Model):
4 first_name = models.CharField(max_length=30)
5 last_name = models.CharField(max_length=30)Ligne 1 imports module "models". I've browse the source code of Django. In the "models" folder, there is a __init__.py file and a lots of .py other files.There is folders too and specially one called "fields".Here is my question :
- When importing models on line 1, doest it import all the .py files in this module, then all classes, Class, functions, variables at the top level of each .py are available for use ? Or there is only an automatic import of the __init__.py ?
Line 4 : : The CharField Class definition is in models/fields/__init__.py. In the code above, there nowhere a reference at "fields". But the line 10 of the the __init__.py in models is " This file is automatically loaded by Python. In this file on line 10, there is "from django.db.models.fields import *". "Here is my question :
- Does it means that the CharField Class is available inside Person Class because there is a cascading import following this way:
- models contains an __init__.py wich import fields and __init.py in fields has a definition of Class CharField on line 601
Hope it's enugh clear ... don't spend much time when it is not and just ask for reformulation, I'll dot it ...RegardsAlain