Saturday, January 28, 2012

Re: Apps vs Project

This was hard for me when I started with Django about a year ago and I'm still learning, but I've found that I prefer to break things down into multiple small apps so that the models.py, admin.py, views.py, tests.py, etc. all are fairly small and easy to understand within a single app. The project settings.py can then just import them each as you would another external app.

See my comments in the thread for the layout and a few tricks that I use:
https://groups.google.com/forum/#!topic/django-users/gNvhuTADOiA

Foreign keys work across app boundaries, you just need to have the apps on your python path and do:

from django.db import models
from crm_customer.models import Customer

class PurchaseOrder(models.Model):
customer = models.ForeignKey(Customer)
...

Also, setting the app_label, you can make all the little applets appear in the same grouping on the admin page and essentially share a namespace for metadata like django-guardian permissions.

class Meta:
app_label = 'crm'


Brian Schott
bfschott@gmail.com

On Jan 12, 2012, at 10:31 AM, Grant Copley wrote:

> Hey guys,
>
> I'm a 12 year ColdFusion guy learning Django and Python and had a
> quick question. If this is the wrong place to post this question, I
> apologize.
>
> I'm interested in converting a Customer relationship management (CRM)
> system currently written in ColdFusion over to Python using Django,
> however the concept of separate apps in a single Django project is
> confusing to me. My CRM system currently manages customers, orders,
> purchase orders, etc... and all of these separate pieces are related.
> For example,
>
> * A customer has many orders
> * A order can result in a purchase order being created
> * etc
>
> My question is, if each piece (customers, orders, ...) ties together,
> should all of this functionality be placed in a Django project with a
> single app, or is it typical to break each piece into into a separate
> app? If you separate them into different apps (an app for customers,
> an app for orders)... then I'm confused how they tie together,
> especially on the model layer.
>
> Thanks,
>
> Grant
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

No comments:

Post a Comment