On 12 Jul, 10:21, james_027 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am following the official tutorial of django, and found out that
> several model are define in a single file. I just wonder if we could
> have one model per file? or can be as flexible as X no of models in
> file A and Y no of models in file B and so on.
>
> If this is allowed, how to we name the files?
>
> Thanks
> james

Within django, models tend to be defined in the models.py file of the
application's directory (/polls/models.py in the tutorial's example).
Although I cannot try this from where I am now, I'm pretty sure you
don't _have_ to do this this way.

As you see later on in the tutorial, you register your application
("polls") in settings.py's INSTALLED_APPS.

In order to use the model classes, you import them, as eg in: from
mysite.polls.models import Polls, Choices

What happens is that django (or rather: python) looks in the directory
where polls resides, gets the models.py file and from there it imports
the classes you want (in this case Polls and Choices). But nothing
prevents you from creating a file called "poll_model.py" in the
"polls" directory and import the Poll class from poll_model.py with
"from mysite.polls.poll_model import Poll".

I don't exactly see what you'd want to do this though. It's a lot
easier to stick to the standard. I do use this for other classes (such
as special form classes), where I create a forms.py file in my
application's directory and import the necessary forms via eg "from
mysite.polls.forms import SpecialForm".

If you're worried about having too many models in one single model.py
file, maybe you should consider splitting up your project in different
applications. It makes the whole development a lot more manageable.

Hope this helps,

mathieu


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to