Where to put domain objects in my application

1k Views Asked by At

So in my python django application the architecture is structured such that it is separated into different apps. One app for users, one for finance, etc.

Each app has the following base structure:

app_name
    models
    services
    tests

I am developing a new feature to support promo codes. Promo codes will allow the user to receive a discount for their upcoming bill(s). So I created a PromoCodeModel and a PromoCodeService. Inside the service I need to check if a user is eligible to redeem this code. It seems like this logic could get fairly complicated and I was hoping to encapsulate the eligibility checks into its own class -- something like PromoCodeEligibility(user, promo_code).

I was wondering -- where would this belong? Should I create a new PromoCodeEligibilityService? Or should I create a new folder called domain and make this a domain object? I could also move this logic into the model itself but having really fat models seems like more of an anti-pattern to me. Thoughts?

1

There are 1 best solutions below

2
Todor On

I could also move this logic into the model itself but having really fat models seems like more of an anti-pattern to me. Thoughts?

Actually this is the preferred way in Django. You can read more about this here and here and here.

PS. I'm pretty sure there were a few sentences about the topic inside django docs, but can't find it.