Thanks Bill F - caught my import error when I tried the second
method.  Just went back & tried the models/ approach; as long as I
import my classes to a models.py file and add 'models' to
INSTALLED_APPS in settings.py syncdb works fine.  So basically I'm
creating a models 'app' without any views to hold my model classes.
It didn't work when I tried importing the classes within the models/
__init__.py file, I must have misunderstood Xavier there.

For the "When in Rome..." comments: sure, point taken.  I can
certainly get used to grouping closely associated classes in a single
file.  But I certainly don't agree ALL classes belong together, common
practice be damned.  I think anyone who's ever worked on a 4000 line
file in some documentation-starved legacy app can see where I'm coming
from.  If it's some little stand-alone utility used by two classes out
of a dozen, for example, why pollute the ONE models.py file with it,
so you have to navigate past it all the time to work on the 90% of
models that don't use it?  That tool belongs in it's own file, or in
utils.py as someone here suggested.  I don't think this format is
SOOOO eccentric that a python purist who comes along later to maintain
my code can't figure it out pretty quickly.

Again, thanks for the advice all.



On Oct 7, 12:03 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> I think that you want:
>
>   from poll import *
>
> in dummy/models/__init__.py
>
> On Fri, Oct 7, 2011 at 11:30 AM, bcrem <billc...@gmail.com> wrote:
> > The separate models/ directory bit didn't work for me; maybe I'm not
> > understanding what you mean exactly?  Here's what I did...
>
> > $ django-admin.py startproject dummy
> > $ cd dummy/
> > $ mkdir models
> > $ vi settings.py
> >  ...filled in my db info...
> > $ cd models
> > $ vi poll.py
> > $ cat models/poll.py
> > from django.db import models
>
> > class Poll(models.Model):
> >   question = models.Charfield(max_length=200)
> >   date = models.DateTimeField('date published')
> > $ vi __init__.py
> > $ cat __init__.py
> > import poll
> > $ cd ..
> > $ python manage.py syncdb
> >  ...created the usual django_* & auth_* tables - but no 'poll' table
>
> > However, importing my classes into an otherwise empty models.py worked
> > fine - syncdb generated the tables I was looking for, no problem.
> > Thanks for the quick response everyone.
>
> > On Oct 7, 10:41 am, Xavier Ordoquy <xordo...@linovia.com> wrote:
> >> Hi,
>
> >> Create a models directory and have an __init__.py file within.
> >> Put the models you want to import in that file and you are good to go.
>
> >> Regards,
> >> Xavier.
>
> >> Le 7 oct. 2011 à 16:39, bcrem a écrit :
>
> >> > Howdy,
>
> >> > I come from a C/C++ background, getting into some django/python now.
> >> > I'm used to a one-class/one-file paradigm, and don't much like
> >> > sticking all the models for an app in models.py.  It's a minor thing,
> >> > I know...
>
> >> > Is there any way to seperate out these classes, and still have syncdb
> >> > pick them up & update your database for you?
>
> >> > Thanks,
> >> > bc
>
> >> > --
> >> > 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 
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group 
> >> > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > 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 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
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 
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