3

I see some similar questions, but they don't appear to be the same or have answers.

I am practicing with Django and trying to make a simple dutch auction project. Initially I thought that the idea would be to create two distinct apps, a buyer app and a seller app, and just have them share databases (or three apps, a commonApp a buyerApp and a sellerApp). However, the more I dig into this the more complicated it seems - I feel like Django isn't really meant to have different apps that are designed around sharing all of their data from one set of tables (maybe I'm wrong?), loosely based on what I've found about having to modify the way Migrations work to accommodate this.

So idea #2, just make one app that separates out the functionality by carefully managing the views, but keeping just one set of models since pretty much all of the data I can think of (the users, the products, etc.) are shared anyway. This seems like it has the advantage of letting Django do all of the data management without my having to sweat about the database design. However, I worry that maybe managing the views will get to be overly complicated.

Maybe there is an idea #3 that makes sense for this sort of project, one that I haven't considered because I am a newb, maybe one that tells me that Django isn't even the right tool for this job...

I tried programming idea #1 and it quickly became spaghetti and only worked when things were very small. I am currently working on idea #2 and so far I think it's going OK, but I'm having trouble conceptualizing how to separate stuff in views, but this could very well just be my lack of experience.

So my question is: is there an obvious resource for this sort of information that I'm missing? If so, could you please point me that way?

2
  • your idea #2 seems accurate. I have multiple projects made in the same manner. Which part is not working? Apr 16, 2017 at 16:53
  • It's not so much that something isn't working, I think it's that I'm not sure how to handle views, commands, queries, etc. in a way that keeps things well-separated and clear between (in this case) sellers and buyers. In some sense I think I need more knowledge to even ask the question clearly. Would a typical Django developer just put, e.g., seller views in one file (like seller_views.py) and buyers views in another so that they don't get mixed up? I guess I'm asking if there is a commonly accepted best practice for such a project/app? Apr 16, 2017 at 17:37

1 Answer 1

7

Inside your Django project:

manage.py startapp sellers
manage.py startapp buyers
manage.py startapp common

Add these three apps to settings.py. Depending on your Django's version it can be just 'sellers', 'buyers', 'common' or 'seller.apps.SellerConfig' and so on.

Write your models in common/models.py, and any other logic related to both apps.

Then, in your seller or buyers views:

from common.models import * # or a particular model

Hope this helps.

3
  • 1
    This works just fine for me, I was just hesitant to move forward with it because it feels against the spirit of Django to have an app that only contains models with no views. But I guess the framework isn't really designed for this sort of application? Apr 17, 2017 at 20:14
  • I think is designed for such types of applications. I personally have one project with 5 apps: One for the customers, one for sellers (users as well, but with different logic), site administrators (those who keep the site running), one for ETL operations and, like in your case, a common app with, well, common logic. Each app has different views, commands and templates. Apr 17, 2017 at 20:36
  • hi each app has its own settings.py like https://gitlab.com/mayan-edms/mayan-edms then is there any blog with some guides on how to integrate? Dec 2, 2020 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.