views:

102

answers:

2

Hello, I'm trying to make a childcare administration app with Django but I've some problems with the payments code.

Each kid has to pay monthly 10 times a year. These payments have some particularities:

  • Some kids could pay a different amount of money depending on the economical situation of the parents.

  • The amount of the payments could change over the year.

  • The payments could be payed in different oportunities.

  • Workshops and food are added to the total value of the payment(they're optional).

I'm having problem in order to model this app. I was thinking about creating a kid model and a payment model:

class Kid(models.Model):
    food = models.BooleanField()
    workshop = models.BooleanField()
    special_price = models.DecimalField(blank=True)

class Payment(models.Model):
    kid = models.ForeignKey(Kid)
    date = models.DateField() 
    amount = models.DecimalField()`

Suppose I want to know in a given date how much moneya kid(the parents) have to pay. I don't know how to solve the changing values problem(the food and workshop values also could change over the year).

Hope you understood me, Thanks. mF.

A: 

No matter how your final models will look like, assuming that you will keep Payment model, you could add to it two fields:

    payment_date = model.DateField()
    already_paid = models.BooleanField()

Then, to get overdue payments, you will be able to make a query:

    Payment.objects.filter(payment_date__lte=datetime.date.today(), already_paid=False)

Having those Payment objects, you will be able to calculate the exact amount.

Tomasz Zielinski
A: 

I would make the payment calculated off of the attributes of the child so by updating the child the payment would change. The payment would not be a entry in the database until it had been paid, the payment would be calculated each time the user requests it.

class Child(object):
   def __init__(self,income,paydate,meals=False,workshops=False):
      self.income = income
      self.paydate = paydate
      ...

I would also have a pricing rules model that in combination with the child object would give you the payment amount. Again updating the PricingRules would change the payment.

class PricingRules(object):
   def __init__(self,income_scale,paydate,meal_price,workshop_price,num_payments):
      ...

I would avoid having a PricingRules object for each Child. There would then be the Payment object

class Payment(object):
   def __init__(self,amount,date_paid):
      ...

I've avoided showing any code that is specific to the ORM being used, I believe the design should stand on its own, and I also like to keep the possibility open of using the objects without the ORM. Using constructors is also my personal style, I like knowing that when an object is created from a class that it will be in a state that is well defined and stable. Without more detail regarding the business logic I have more questions than answer beyond this point.

lewisblackfan