Django: need help getting apps dependent on each other

I am working on a website that will help private teachers manage their students, and part of this will keep track of how much money is owed to him.

I want my applications to be reused and not dependent on each other. So, I created one application whose responsibility is CRUD of student, teacher and parent objects (all these models have a foreign key for the user, so they look like a user profile, but I do not use the built-in user profile system). There is also a family model that associates student objects with parent objects. I also created a separate application responsible for managing accounts, accounts and positions.

My problem is integrating the two. I have a basic template in an account application based on a general view that lists account objects and their balances. What I want to do in this template is to group accounts by families and show totals for all accounts that belong to a particular family.

How can this be done if the applications are independent of each other?

+4
source share
1 answer

Here is what I'm still working on:

class AccountGroup(models.Model): accounts = models.ManyToManyField(Account) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') 

Documented here . This way, accounts can be grouped into whatever they have in other applications. In my case, when I create an account group, I set the content_type to family, and object_id to the specific family instance that needs to be grouped. The view is a simple wrapped general view.

0
source

Source: https://habr.com/ru/post/1310531/


All Articles