HI Dan,

Thanks for your response but that will not solve my problem.

I am not splitting models. I am splitting actions defined in the
models  across multiple files.

So suppose

one of my model actions is calling which in turn calls the constructor
or simple functions defined in normal python files

for ex:

def action (self, request, queryset):

    Test1(<params>)     //calls default constructor of the class
    Test2(<params>)

Now each of these are separate class files names as Test1.py Test2.py.

In each of these files i want to do this

from <project_name>.<app name>.models import <class name>

But I get this error

ImportError: cannot import name <class name>

I tired various other variotions like just

from models import <class name>

from <app name>.models import <class name>

or without from

but none of them are working.

Also, in order to call this Test1(<params>) I thought if  I import
Test1 in models then it will just work but again not

--RJ



On Thu, Jun 10, 2010 at 1:57 PM, Dan Harris <[email protected]> wrote:
> When you split things out into multiple files or directories you have
> to remember to import them into the models.py file or the __init__.py
> file (if using a directory).
>
> So if i had some models in a new file "extraModels.py" for example
>
> # In extraModels.py
> class ExtraModel(models.Model):
>    pass
>
> Then in the regular "models.py"
>
> # In models.py
> from extraModels import ExtraModel
>
> class RegularModels(model.Model):
>   pass
>
> The key is that you ahve to import any models in your split files into
> your normal models.py file. This is because Django looks for models in
> the models.py file only. If you make a models directory, you have to
> import all models you want Django to recognize into your __init__.py
> file within the models directory.
>
> Hopefully this makes sense, if not I can try to be more clear.
>
> Dan Harris
> [email protected]
>
>
> On Jun 10, 4:46 pm, rahul jain <[email protected]> wrote:
>> anyone on this ??
>>
>> --RJ
>>
>>
>>
>> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[email protected]> wrote:
>> > Hi Django,
>>
>> > In my app directory, I splitted my models and views.py into multiple
>> > files since they start becoming very long but django is not able to
>> > recognize those files .
>> > It only recognizes models.py, views.py, tests.py (default ones).
>>
>> > So In my other files If i do this
>>
>> > from <project_name>.<app name>.models import <class name>
>>
>> > I get this error
>>
>> > ImportError: cannot import name <class name>
>>
>> > If I do the same on views.py, it just works fine.
>>
>> > Even on Eclipse I can see Django default files with different symbol
>> > and python files with different symbols.
>>
>> > How to solve this problem ?
>>
>> > --RJ
>
> --
> 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.

Reply via email to