On Wed, Aug 23, 2017 at 4:40 PM, Alexander Joseph <
alexander.v.jos...@gmail.com> wrote:

> One more question - is there a way to put apps in folders/sub-folders
> instead of creating sub-apps/modules? I just want to keep things easier to
> navigate on the development side. I will eventually have about 20 sub-apps
> in the 'Engineering' app alone.
>
> Even if I could just group all the engineering sub-apps i have now under
> an engineering folder without any further hierarchy that would help as
> there will also be HR, financial apps, administration apps, etc.
>
> Thanks again
>

Technically you can go as deep as you'd like. You can use the module
strategy to emulate a Django 'app' without all the registration fuss. A
couple abbreviated examples:


# 1. Group resources and references by object type
project/
    engineering/
        __init__.py
        models/
            __init__.py
             widgets.py
             gadgets.py
             product1.py
             product2.py
        views/
            __init__.py
            product1.py
            product2.py
     # etc.

All of the models for engineering would be grouped in a single 'models'
module. Imports would look like 'from engineering.models.widgets import
WonderWidget'

The engineering/models/__init__.py file would contain lines like 'from
.widgets import *' for all of your files that contain models.


# 2. Group by business segment or workflow
project/
    engineering/
        __init__.py
        models.py
        product1/
            __init__.py
            models.py
            views.py
            urls.py
        product2/
            __init__.py
            models.py
            views.py
            urls.py
     # etc.

In this case, you're replicating the structure of an 'app' without creating
one by Django's definition. The engineering/models.py file would then
contain imports like 'from .product1.models import *' in order to get the
model auto-discovery to work correctly.

I'm under the impression that most developers use layout #1, but a large
project might work better with #2 if there aren't a lot of
cross-dependencies.

Note that using Python modules rather than real Django apps will also keep
your settings.INSTALLED_APPS list minimized. With as many 'apps' as you
were originally talking about, that list could be dozens or hundreds of
items long.

IMHO I would start with #1 and see how it works for you. It could be the
generalized term 'product' that you're using, but to me, a product would
not trigger a new 'app' for me, just extra model/view/url/etc. files,
especially given how often products change or are added/removed. In that
case, #2 might work better since all of the related code is within a single
sub-folder (but all the references to that code aren't, so there is still
work to be done). YMMV

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWr9GGYERPYDAYHvYdryRMq5NkWN3ws1zaKw8MxusoGJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to