1

I am new to Django and have a little problem with making all the project structure clear and organized and so on.. The MVC stuff in Django is quite easy to use when making a small project. However, when I am trying to get a new layer (application logic, like three-tier architecture) between views.py and models.py I have problem to do so.

I have the following structure:

  • mysite/
    • manage.py
    • app1/
      • models.py
      • views.py
      • logic/
        • __init__.py
        • Class1.py
        • parser.py
    • ...

and I want to load into views.py stuff from Class1.py and parser.py. How do I do it?

Neither of the following works:

from app1.logic import *

from app1.logic.Class1 import Class1

Also, it would help me if somebody could list me some example of a really huge django project. It looks like either lots of classes and .py files should be in every app folder or everything is in the models.py.. Both look a little disorganised and I'm sure there is a way to make it a little bit clearer (like in Zend or Symfony).

And, I'm working with Python3 and Django 1.5b2.

Thanks.

Jakub Žitný
  • 962
  • 1
  • 9
  • 38
  • if you have `__init__.py`, youshould be able to import it. Are you able to import it in the shell? – Amyth Jan 03 '13 at 19:55
  • 1
    What is `screenshots`? Do you mean `mysite`? – Daniel Roseman Jan 03 '13 at 20:03
  • Sorry, I meant app1... And in the shell I'm able to import it.. I think there could be problem with relative importing.. when I'm inside the app1, console can import the modules, but when django calls views through x other files/layers, the path is somehow changed or something.. Could be? – Jakub Žitný Jan 03 '13 at 21:19

1 Answers1

0

If Class1 or parser import from views, then you have a circular dependency. You'll need to move any shared code out into a third file.

You might consider though whether you need all those separate files under logic. In Python there's no requirement to have a class in its own file, so maybe you could have a single logic.py instead of a logic directory containing several files.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Yup, I know that. But then I'd have in one `logic.py` huge huge number of classes and that's the "problem" I'm trying to solve. – Jakub Žitný Jan 03 '13 at 23:31