On Sunday, 16 October 2011 23:43:56 UTC+1, youpsla wrote:
>
> Hello, 
> I'm new to Django and I've only a medium background in funtionnal 
> programming in Python. 
>
> I'm currently reading and working on the Django tutorial. I've few 
> questions on a example of code because things are not so clear for me. 
>
> Here is the code example 
>
> 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) 
>
> Can you say me if I'm wrong or not on the followings: 
>
> - line 1 : Import of the" models" method from the "django.db" 
> module ? 
>
> - line 3 : Définition of the "Person" classs wich heritates from the 
> "models.Model class ? If true, and assuming that "models" is a method, 
> a class can be nested in a method ? 
>
> - ligne 4 : Creation of variable "first_name" by calling the method 
> CharField with one argument. But how "CharFiled" is written, isn't it 
> a class ? ANd here we use only "models", then why on line 3 we use 
> "models.Model" ? 
>
> I hope it's not to much confusing !!!! :-) 
>
> Help would be REALLY appreciated !!! 
>
> Regards 
>
> Alain



This is fairly basic stuff - sounds like you would benefit from doing an 
introductory Python tutorial.

At the root of your confusion, I think, is that you're mixing up methods and 
modules. `models` in the code above is a module[*] containing multiple 
classes. You can't import a method, as that's simply a function belonging to 
a class. You can import modules - `from django.db import models` - or 
elements such as classes and constants directly inside a module - `from 
django.db.models import Model`.

So, the `models` module includes a class named Model, and also several other 
classes which represent fields - CharField, BooleanField, etc. All of these 
live directly inside the models namespace, so are referred to in exactly the 
same way - models.Model, models.CharField, etc.
--
DR.

[*] Yes, strictly speaking it's a package, but that's probably too confusing 
at this stage

-- 
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/-/m39fNeqPf_YJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to