Re: not able to recognize non-default python files in app + project directory
Apologies for the "__initial__" stuff -- damn iPhone autocomplete! On Jun 11, 11:15 am, rahul jain 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 > > --RJ > > > > On Fri, Jun 11, 2010 at 7:59 AM, Tom Evans wrote: > > On Fri, Jun 11, 2010 at 3:47 PM, rahul jain 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 django-us...@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-us...@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.
Re: not able to recognize non-default python files in app + project directory
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 --RJ On Fri, Jun 11, 2010 at 7:59 AM, Tom Evans wrote: > On Fri, Jun 11, 2010 at 3:47 PM, rahul jain 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 django-us...@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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: not able to recognize non-default python files in app + project directory
On Fri, Jun 11, 2010 at 3:47 PM, rahul jain 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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
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 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 django-us...@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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: not able to recognize non-default python files in app + project directory
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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
@also I meant .objects. all(). It will give import error that cannot be imported. On Fri, Jun 11, 2010 at 7:09 AM, rahul jain 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 >> .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 wrote: >> @bruno: yes functions. >> >> So in some other file I want to use models methods like >> >> .objects. all >> >> For that I have to import the . 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 >> .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 wrote: >>> Yes they are in the same directory. How to use __initial__.py ? >>> >>> On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould 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 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() //calls default constructor of the class > Test2() > > 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 ..models import > > But I get this error > > ImportError: cannot import name > > I tired various other variotions like just > > from models import > > from .models import > > or without from > > but none of them are working. > > Also, in order to call this Test1() 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 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 > > dih0...@gmail.com > > > On Jun 10, 4:46 pm, rahul jain wrote: > >> anyone on this ?? > > >> --RJ > > >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain > >> 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 ..models import > > >> > I get this error > > >> > ImportError: cannot import 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 django-us...@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
Re: not able to recognize non-default python files in app + project directory
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 > .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 wrote: > @bruno: yes functions. > > So in some other file I want to use models methods like > > .objects. all > > For that I have to import the . 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 > .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 wrote: >> Yes they are in the same directory. How to use __initial__.py ? >> >> On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould 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 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() //calls default constructor of the class Test2() 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 ..models import But I get this error ImportError: cannot import name I tired various other variotions like just from models import from .models import or without from but none of them are working. Also, in order to call this Test1() 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 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 > dih0...@gmail.com > On Jun 10, 4:46 pm, rahul jain wrote: >> anyone on this ?? >> --RJ >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain >> 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 ..models import >> > I get this error >> > ImportError: cannot import 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 django-us...@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-us...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> django-users+unsubscr...@googlegroups.com. >>> For more optio
Re: not able to recognize non-default python files in app + project directory
@bruno: yes functions. So in some other file I want to use models methods like .objects. all For that I have to import the . 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 .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 wrote: > Yes they are in the same directory. How to use __initial__.py ? > > On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould 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 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() //calls default constructor of the class >>> Test2() >>> >>> 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 ..models import >>> >>> But I get this error >>> >>> ImportError: cannot import name >>> >>> I tired various other variotions like just >>> >>> from models import >>> >>> from .models import >>> >>> or without from >>> >>> but none of them are working. >>> >>> Also, in order to call this Test1() 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 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 >>> > dih0...@gmail.com >>> >>> > On Jun 10, 4:46 pm, rahul jain wrote: >>> >> anyone on this ?? >>> >>> >> --RJ >>> >>> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain >>> >> 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 ..models import >>> >>> >> > I get this error >>> >>> >> > ImportError: cannot import 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 django-us...@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-us...@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. >> >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: not able to recognize non-default python files in app + project directory
On Fri, Jun 11, 2010 at 2:53 PM, rahul jain 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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
Yes they are in the same directory. How to use __initial__.py ? On Fri, Jun 11, 2010 at 3:38 AM, Scott Gould 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 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() //calls default constructor of the class >> Test2() >> >> 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 ..models import >> >> But I get this error >> >> ImportError: cannot import name >> >> I tired various other variotions like just >> >> from models import >> >> from .models import >> >> or without from >> >> but none of them are working. >> >> Also, in order to call this Test1() 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 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 >> > dih0...@gmail.com >> >> > On Jun 10, 4:46 pm, rahul jain wrote: >> >> anyone on this ?? >> >> >> --RJ >> >> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain >> >> 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 ..models import >> >> >> > I get this error >> >> >> > ImportError: cannot import 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 django-us...@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-us...@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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: not able to recognize non-default python files in app + project directory
On 10 juin, 23:18, rahul jain 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 > 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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
On 11 juin, 12:38, Scott Gould 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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
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 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() //calls default constructor of the class > Test2() > > 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 ..models import > > But I get this error > > ImportError: cannot import name > > I tired various other variotions like just > > from models import > > from .models import > > or without from > > but none of them are working. > > Also, in order to call this Test1() 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 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 > > dih0...@gmail.com > > > On Jun 10, 4:46 pm, rahul jain wrote: > >> anyone on this ?? > > >> --RJ > > >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain > >> 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 ..models import > > >> > I get this error > > >> > ImportError: cannot import 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 django-us...@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-us...@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.
Re: not able to recognize non-default python files in app + project directory
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 dih0...@gmail.com On Jun 10, 4:46 pm, rahul jain wrote: > anyone on this ?? > > --RJ > > > > On Thu, Jun 10, 2010 at 11:34 AM, rahul jain 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 ..models import > > > I get this error > > > ImportError: cannot import 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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
anyone on this ?? --RJ On Thu, Jun 10, 2010 at 11:34 AM, rahul jain 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 ..models import > > I get this error > > ImportError: cannot import 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 django-us...@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.
Re: not able to recognize non-default python files in app + project directory
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() //calls default constructor of the class Test2() 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 ..models import But I get this error ImportError: cannot import name I tired various other variotions like just from models import from .models import or without from but none of them are working. Also, in order to call this Test1() 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 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 > dih0...@gmail.com > > > On Jun 10, 4:46 pm, rahul jain wrote: >> anyone on this ?? >> >> --RJ >> >> >> >> On Thu, Jun 10, 2010 at 11:34 AM, rahul jain 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 ..models import >> >> > I get this error >> >> > ImportError: cannot import 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 django-us...@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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
not able to recognize non-default python files in app + project directory
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 ..models import I get this error ImportError: cannot import 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 django-us...@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.