2

I'm very new to django and python as well. I want to try out a project written in django.

Let say the project have 3 modules

  1. User
    • CRUD
    • Forgot password
    • login
  2. Booking
    • CRUD
    • Search
  3. Default (basically is for web users to view)
    • Home page
    • about us

All these have different business logic for the same entity.

Should I create 3 apps for this? If 3 different apps, then the table name is all different as it will automatic add a prefix for table name.

Any suggestion?

Js Lim
  • 3,625
  • 6
  • 42
  • 80

4 Answers4

2

There's really no correct answer to this. In general, the way in which you break down any programming task into 'modules' is very much a matter of personal taste.

My own view on the subject is to start with a single module, and only break it into smaller modules when it becomes 'necessary', e.g. when a single module becomes excessively large.

With respect to the apps, if all the apps share the same database tables, you'll probably find it easier to do everything in a single app. I think using multiple Django apps is only really necessary when you want to share the same app between multiple projects.

Aya
  • 39,884
  • 6
  • 55
  • 55
1

I agree in @aya answer and I also supported your structure for multiple modules. In my project, I created 18 apps. Each app perform different rules:

 1. accounts 
      - login
      - forgot password
      - register
      - profile
 2. common
      //in here all the common function use by different apps
 3. front
      - home
      - testimonial
 4. guides
      //tutorials

And lots more apps...

I arrange this way so that it will be easy to trace, debug, and find the codes. If your problem is the name of table you can set the class Meta of db_table.

catherine
  • 22,492
  • 12
  • 61
  • 85
  • I have also created different settings for development, local, heroku, production, etc. – catherine Apr 11 '13 at 14:41
  • so what about the model class? Let say for User model I want to use in both modules, should it be 2 separate files or just one global file? – Js Lim Apr 12 '13 at 08:54
  • 1
    @JsLim my apps have different model_class, form_class, and so on. If I call model in different modules I just import it or like I did before because of being lazy in typing I use get_model to call all my model_class in different modules. But now I prefer to import it, to have a clean and arrange codes. You can also use relative imports to lessen the import line. Also I do inheritance, so that I cannot violate the DRY principle. there are many ways to lessen the codes – catherine Apr 12 '13 at 09:14
0

I am relatively new to Django and Python myself too. In practice, try to have your Django apps do one thing and do it well. If you find that an app is becoming more and more complex, it may be worth splitting this out into multiple apps.

I would not worry about the DB tablename as Django handles the DB interaction for you. If you name your apps and models well, your code should be fairly self documenting.

I have recently learnt a lot of "best practices" in how to setup and layout Django projects from the ebook 2 Scoops of Django. I am not affiliated with them in any way, but have just learnt a lot from it.

Also, definitely run through the Django tutorial if you haven't already.

Hope this has helped!

SWilder
  • 817
  • 7
  • 11
  • There is also another tutorial posted recently on NetTuts at http://net.tutsplus.com/tutorials/python-tutorials/building-ribbit-with-django/?search_index=16 – SWilder Apr 11 '13 at 14:29
  • thanks for the comment. I have gone through some of the official tutorial, but it only show the basic thing. That's why I post a question here. – Js Lim Apr 12 '13 at 09:02
0

Focus on making your apps reusable. This way you will save significant number of time in your next project. Good article about it is available at the Django's website.

If you have closely integrated modules or depending on each other, then there's no real benefit of having them in separate apps, because you won't ever use them separately. Organizing in separate Python modules will be just fine.

Also do not think about "how will my tables be named" when you consider project organization. Tables can be easily renamed while bad design will make you trouble as the project will grow.

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162