Something I've seen that isn't particularly well documented (if at all)...
If you have a model that isn't in your foo.models (ie, the top models.py
for the app), and have a package setup, you need to add an app_name
property to your model classes.
Example
myproject/
foo_app/ <-- needs to be in the python path, else you'll have to
prefix app_name with the project name
__init__.py
models/
__init__.py
some_models.py
(inside some_models.py)
class MyModel(models.Model)
app_name = 'foo_app' # 'foo_app' if the app is in python path, else
'myproject.foo_app'
In my case, syncdb wouldn't "see" any models for my app I didn't do
this, and they weren't in the main models.py
Bill Freeman wrote:
> Does your __init__.py import the otehr files, or does it import the
> models from them? If the former, then model Foo in foo.py of
> the models package of app bar must be referred to as
> bar.models.foo.Foo, whereas in the later case, as with having
> everything in a models.py file, bar.models.Foo will work.
>
> One answer to this would be an __all__ not in __init__.py, but
> in foo.py, specifying the model, and then using:
> from foo import *
> in __init__.py, rather than:
> import foo
>
> There might be other problems, but things will have a better
> chance if the interesting stuff is in the bar.models namespace
> directly.
>
> On Sat, May 1, 2010 at 1:45 AM, akonsu <[email protected]> wrote:
>
>> hello,
>>
>> i would like to replace my models.py with a package that has a
>> hierarchical directory structure. in __init__.py i want to define my
>> base models, and the other files would contain models that inherit the
>> base models.
>>
>> in particular i am trying to define proxy models for my models and put
>> them in to separate files.
>>
>> the problem is that the user admin system's "change user" screen does
>> not list the permissions for proxies if they are located in separate
>> files. if i put proxy classes in to __init__.py and re-run syncdb,
>> then the permissions get listed. otherwise not. i tried creating
>> __all__ array in my __init__.py that includes the proxy files, and i
>> tried importing the files in to __init__.py to no avail.
>>
>> how can this be done?
>>
>> thanks
>> konstantin
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> 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.
>>
>>
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
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.