I am working on a billing and accounting application from scratch in which I have created two different apps as:
Now I have a issue I need to relate both of them in the following situations:
I have tried using the foreign keys in the models among these apps but it just looks very crude and bad.
I am not sure wether I should put all the models in the same or so; I would like to have a review on my design by someone insightful so that I can know what are the better ways of doing this.
Django comes with six built-in apps that we can examine.
Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.
It's perfectly fine. To avoid import loops you can use string definitions;
module 'foo/models.py'
class Foo(models.Model):
bar = models.ForeignKey('bar.Bar') # no explicit import statement required
module 'bar/models.py'
class Bar(models.Model):
foo = models.ForeignKey('foo.Foo')
The real question is does your structure make things more intuitive? If you're unsure why you need to split depended pieces of code, don't.
Related topic: Separation of business logic and data access in django
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With