not able to recognize non-default python files in app + project directory

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

not able to recognize non-default python files in app + project directory

rahul jain-9
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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
anyone on this ??

--RJ

On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

Dan Harris-4
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
[hidden email]


On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:

> anyone on this ??
>
> --RJ
>
>
>
> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
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 <[hidden email]> 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
> [hidden email]
>
>
> On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:
>> anyone on this ??
>>
>> --RJ
>>
>>
>>
>> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

Scott Gould
Did you put Test1.py and Test2.py into a "models" directory where
models.py would normally be, and add an __initial__.py file to it?

On Jun 10, 5:18 pm, rahul jain <[hidden email]> wrote:

> 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 <[hidden email]> 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
> > [hidden email]
>
> > On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:
> >> anyone on this ??
>
> >> --RJ
>
> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
> > To unsubscribe from this group, send email to [hidden email].
> > 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

bruno desthuilliers-7


On 11 juin, 12:38, Scott Gould <[hidden email]> wrote:
> Did you put Test1.py and Test2.py into a "models" directory where
> models.py would normally be, and add an __initial__.py file to it?
>

s/__initial__/__init__/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

bruno desthuilliers-7
In reply to this post by rahul jain-9

On 10 juin, 23:18, rahul jain <[hidden email]> wrote:
> HI Dan,
>
> Thanks for your response but that will not solve my problem.
>
> I am not splitting models. I am splitting actions

I assume you mean "functions" ?

> defined in the
> models  across multiple files.

(snip)

>
> But I get this error
>
> ImportError: cannot import name <class name>
>

http://docs.python.org/tutorial/modules.html

HTH

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
In reply to this post by Scott Gould
Yes they are in the same directory. How to use __initial__.py ?

On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould <[hidden email]> wrote:

> Did you put Test1.py and Test2.py into a "models" directory where
> models.py would normally be, and add an __initial__.py file to it?
>
> On Jun 10, 5:18 pm, rahul jain <[hidden email]> wrote:
>> 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 <[hidden email]> 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
>> > [hidden email]
>>
>> > On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:
>> >> anyone on this ??
>>
>> >> --RJ
>>
>> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
>> > To unsubscribe from this group, send email to [hidden email].
>> > 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 [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

Tom Evans-3
On Fri, Jun 11, 2010 at 2:53 PM, rahul jain <[hidden email]> wrote:
> Yes they are in the same directory. How to use __initial__.py ?
>

It's called __init__.py. It must exist in any python module
(directory), and need not contain anything.

You were linked to this earlier in the thread, I suggest you read it!

http://docs.python.org/tutorial/modules.html

HTH

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
In reply to this post by rahul jain-9
@bruno: yes functions.

So in some other file I want to use models methods like

<Model>.objects. all

For that I have to import the <Model> . But I am not able to.

Import works fine on views.py

Also, can you test this for me

Create views1.py (not views.py)

import your model class

and in one of the functions do
<Model>.objects. all

and then run python manage.py runserver. I think it will break.

Let me know what i am missing or will __initial__.py will solve this
problem   ?.





On Fri, Jun 11, 2010 at 6:53 AM, rahul jain <[hidden email]> wrote:

> Yes they are in the same directory. How to use __initial__.py ?
>
> On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould <[hidden email]> wrote:
>> Did you put Test1.py and Test2.py into a "models" directory where
>> models.py would normally be, and add an __initial__.py file to it?
>>
>> On Jun 10, 5:18 pm, rahul jain <[hidden email]> wrote:
>>> 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 <[hidden email]> 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
>>> > [hidden email]
>>>
>>> > On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:
>>> >> anyone on this ??
>>>
>>> >> --RJ
>>>
>>> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
>>> > To unsubscribe from this group, send email to [hidden email].
>>> > 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 [hidden email].
>> To unsubscribe from this group, send email to [hidden email].
>> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
Yes I have the __init__.py inside my app directory. Also, all my split
files are inside the same directory. If possible can you test

Create views1.py (not views.py)
>
> import your model class
>
> and in one of the functions do
> <Model>.objects. all()
>
> and then run python manage.py runserver. I think it will break.



--RJ

On Fri, Jun 11, 2010 at 7:04 AM, rahul jain <[hidden email]> wrote:

> @bruno: yes functions.
>
> So in some other file I want to use models methods like
>
> <Model>.objects. all
>
> For that I have to import the <Model> . But I am not able to.
>
> Import works fine on views.py
>
> Also, can you test this for me
>
> Create views1.py (not views.py)
>
> import your model class
>
> and in one of the functions do
> <Model>.objects. all
>
> and then run python manage.py runserver. I think it will break.
>
> Let me know what i am missing or will __initial__.py will solve this
> problem   ?.
>
>
>
>
>
> On Fri, Jun 11, 2010 at 6:53 AM, rahul jain <[hidden email]> wrote:
>> Yes they are in the same directory. How to use __initial__.py ?
>>
>> On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould <[hidden email]> wrote:
>>> Did you put Test1.py and Test2.py into a "models" directory where
>>> models.py would normally be, and add an __initial__.py file to it?
>>>
>>> On Jun 10, 5:18 pm, rahul jain <[hidden email]> wrote:
>>>> 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 <[hidden email]> 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
>>>> > [hidden email]
>>>>
>>>> > On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:
>>>> >> anyone on this ??
>>>>
>>>> >> --RJ
>>>>
>>>> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
>>>> > To unsubscribe from this group, send email to [hidden email].
>>>> > 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 [hidden email].
>>> To unsubscribe from this group, send email to [hidden email].
>>> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
@also I meant <Model>.objects. all().

It will give import error that <Model> cannot be imported.



On Fri, Jun 11, 2010 at 7:09 AM, rahul jain <[hidden email]> wrote:

> Yes I have the __init__.py inside my app directory. Also, all my split
> files are inside the same directory. If possible can you test
>
> Create views1.py (not views.py)
>>
>> import your model class
>>
>> and in one of the functions do
>> <Model>.objects. all()
>>
>> and then run python manage.py runserver. I think it will break.
>
>
>
> --RJ
>
> On Fri, Jun 11, 2010 at 7:04 AM, rahul jain <[hidden email]> wrote:
>> @bruno: yes functions.
>>
>> So in some other file I want to use models methods like
>>
>> <Model>.objects. all
>>
>> For that I have to import the <Model> . But I am not able to.
>>
>> Import works fine on views.py
>>
>> Also, can you test this for me
>>
>> Create views1.py (not views.py)
>>
>> import your model class
>>
>> and in one of the functions do
>> <Model>.objects. all
>>
>> and then run python manage.py runserver. I think it will break.
>>
>> Let me know what i am missing or will __initial__.py will solve this
>> problem   ?.
>>
>>
>>
>>
>>
>> On Fri, Jun 11, 2010 at 6:53 AM, rahul jain <[hidden email]> wrote:
>>> Yes they are in the same directory. How to use __initial__.py ?
>>>
>>> On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould <[hidden email]> wrote:
>>>> Did you put Test1.py and Test2.py into a "models" directory where
>>>> models.py would normally be, and add an __initial__.py file to it?
>>>>
>>>> On Jun 10, 5:18 pm, rahul jain <[hidden email]> wrote:
>>>>> 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 <[hidden email]> 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
>>>>> > [hidden email]
>>>>>
>>>>> > On Jun 10, 4:46 pm, rahul jain <[hidden email]> wrote:
>>>>> >> anyone on this ??
>>>>>
>>>>> >> --RJ
>>>>>
>>>>> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain <[hidden email]> 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 [hidden email].
>>>>> > To unsubscribe from this group, send email to [hidden email].
>>>>> > 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 [hidden email].
>>>> To unsubscribe from this group, send email to [hidden email].
>>>> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

Tom Evans-3
I'll give you the benefit of the doubt since it seems some of this is
getting lost in translation.

Your app must have this sort of structure:

app
|-- __init__.py
|-- models
|   |-- __init__.py
|   |-- auth.py
|   `-- blogs.py
`-- views.py


If app/models/auth.py defines a User class, and app/models/blogs.py
defines a Blog class, then in app/views.py you would refer to them
like this:

from app.models.auth import User
from app.models.blog import Blog

You cannot refer to them like so:

from app.models import *

unless you first import them into app/models/__init__.py.

This is well documented python semantics; read the python docs for
more information.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
Hi Tim,

Here is my structure

app
|-- __init__.py
|-- models.py (all  my models)
|-- auth.py  (python functions referencing models defined in models.py)
|-- blogs.py (python functions referencing models defined in models.py)
|-- views.py (python functions referencing models defined in models.py)


for auth.py and blogs.py referencing is giving import error.

Again in these files. If I do import like

from app.models import User then I get import error.

For views.py I am able to easily import @above.

--RJ






On Fri, Jun 11, 2010 at 7:18 AM, Tom Evans <[hidden email]> wrote:

> I'll give you the benefit of the doubt since it seems some of this is
> getting lost in translation.
>
> Your app must have this sort of structure:
>
> app
> |-- __init__.py
> |-- models
> |   |-- __init__.py
> |   |-- auth.py
> |   `-- blogs.py
> `-- views.py
>
>
> If app/models/auth.py defines a User class, and app/models/blogs.py
> defines a Blog class, then in app/views.py you would refer to them
> like this:
>
> from app.models.auth import User
> from app.models.blog import Blog
>
> You cannot refer to them like so:
>
> from app.models import *
>
> unless you first import them into app/models/__init__.py.
>
> This is well documented python semantics; read the python docs for
> more information.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

Tom Evans-3
On Fri, Jun 11, 2010 at 3:47 PM, rahul jain <[hidden email]> wrote:

> Hi Tim,
>
> Here is my structure
>
> app
> |-- __init__.py
> |-- models.py (all  my models)
> |-- auth.py  (python functions referencing models defined in models.py)
> |-- blogs.py (python functions referencing models defined in models.py)
> |-- views.py (python functions referencing models defined in models.py)
>
>
> for auth.py and blogs.py referencing is giving import error.
>
> Again in these files. If I do import like
>
> from app.models import User then I get import error.
>
> For views.py I am able to easily import @above.
>
> --RJ
>

That all looks correct. Are the file permissions correct?

Can you show 'ls -l /path/to/app/' please.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

rahul jain-9
It was rw-r--r-- . I also modified it to 777 by" chmod -R 777". But
did not fix my problem.

This is the error which I am getting
ImportError: cannot import name <Model Name>

--RJ


On Fri, Jun 11, 2010 at 7:59 AM, Tom Evans <[hidden email]> wrote:

> On Fri, Jun 11, 2010 at 3:47 PM, rahul jain <[hidden email]> wrote:
>> Hi Tim,
>>
>> Here is my structure
>>
>> app
>> |-- __init__.py
>> |-- models.py (all  my models)
>> |-- auth.py  (python functions referencing models defined in models.py)
>> |-- blogs.py (python functions referencing models defined in models.py)
>> |-- views.py (python functions referencing models defined in models.py)
>>
>>
>> for auth.py and blogs.py referencing is giving import error.
>>
>> Again in these files. If I do import like
>>
>> from app.models import User then I get import error.
>>
>> For views.py I am able to easily import @above.
>>
>> --RJ
>>
>
> That all looks correct. Are the file permissions correct?
>
> Can you show 'ls -l /path/to/app/' please.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: not able to recognize non-default python files in app + project directory

Scott Gould
Apologies for the "__initial__" stuff -- damn iPhone autocomplete!

On Jun 11, 11:15 am, rahul jain <[hidden email]> wrote:

> It was rw-r--r-- . I also modified it to 777 by" chmod -R 777". But
> did not fix my problem.
>
> This is the error which I am getting
> ImportError: cannot import name <Model Name>
>
> --RJ
>
>
>
> On Fri, Jun 11, 2010 at 7:59 AM, Tom Evans <[hidden email]> wrote:
> > On Fri, Jun 11, 2010 at 3:47 PM, rahul jain <[hidden email]> wrote:
> >> Hi Tim,
>
> >> Here is my structure
>
> >> app
> >> |-- __init__.py
> >> |-- models.py (all  my models)
> >> |-- auth.py  (python functions referencing models defined in models.py)
> >> |-- blogs.py (python functions referencing models defined in models.py)
> >> |-- views.py (python functions referencing models defined in models.py)
>
> >> for auth.py and blogs.py referencing is giving import error.
>
> >> Again in these files. If I do import like
>
> >> from app.models import User then I get import error.
>
> >> For views.py I am able to easily import @above.
>
> >> --RJ
>
> > That all looks correct. Are the file permissions correct?
>
> > Can you show 'ls -l /path/to/app/' please.
>
> > Cheers
>
> > Tom
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to [hidden email].
> > 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 [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.