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 <[email protected]> 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 <[email protected]> wrote:
>> Yes they are in the same directory. How to use __initial__.py ?
>>
>> On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould <[email protected]> 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 <[email protected]> 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 <[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 
>>>> > 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 [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