Django. One app with many models vs. many apps with single model

后端 未结 5 1810
眼角桃花
眼角桃花 2020-12-08 00:42

I\'m currently developing my own weblog in Django. But I\'ve already stucked right in the beginning. So, here is my tree hierarchy:

/pyroot/nemo         


        
5条回答
  •  情歌与酒
    2020-12-08 01:04

    The rule of thumb is than an "app" should be a complete piece of functionality. If your blog cannot run without tags (like literally, not just it would be nicer to have a blog with tags than without) then tags should be part of the blog app.

    However, there's no clear-cut answer here. Some app-purists focus entirely on re-usability and make each app a discrete piece of functionality with little to no dependencies on anything else. Some create entire applications with a single Django app. It's really up to you to decide what makes the most sense in your particular scenario.

    In general, I would say combine functionality that won't likely be used else, but is required for the app, all in the same app. Things like tags or comments are probably candidates for their own apps, and indeed, you can find many such apps available that can be simply plugged into your app to provide that functionality.

    In any app more complicated than a simple to-do list, you're pretty much inevitably going to end up with a good deal of crossover, though. There's no one right answer. Just use common sense and think DRY (don't repeat yourself) and you'll do okay.

提交回复
热议问题