On Monday, 17 October 2011 15:00:09 UTC+1, youpsla wrote: > > Hello Daniel > thanks 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 ? > > Only the __init__.py. But...
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 > > Yes, this is exactly right. > Hope it's enugh clear ... don't spend much time when it is not and just ask > for reformulation, I'll dot it ... > Regards > > Alain > > > You might like to read the effbot's explanation of the different import methods: http://effbot.org/zone/import-confusion.htm -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/AVl4aUs9D-oJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

