views:

59

answers:

1

heya,

This is a fairly quick question regarding schema design for a Django project.

Basically, we have a series of monthly reports from different departments that are aggregated into a single report with some pretty charts (we're probably going to use Google Visualization API for that, but I'm open to other suggestions, if you think something else integrates nicely with Django).

Each department is responsible for filing their own figures for their part of the report. We'll probably be using the Django admin for entering in those figures, since it doesn't have to be pretty, it's just to get some numbers in each month.

I'm assuming the better way here is to have an abstract Report model, inherit this for each department having a separate Model, with any specific fields overridden, and then have a DateField on each one as well.

Having a month as the parent object, and descending the reports from that - that's a silly approach, right?

Also, what's the best way of enforcing it so that they can only submit their figures once? I could have a separate month and year field, I guess and enforce a unique on that field, but I was hoping to use the inbuilt DateField, but what's the best way to enforce month and year uniqueness? Should I use the new model validation feature for that?

Cheers, Victor

+1  A: 

A Django model field can have an option unique_for_month and unique_for_year. The value of that option is a DateTime or Date field in the model.

E.g.

class Report(models.Model):
    submit_date = models.DateField()
    department_id = models.IntegerField(unqiue_for_month=date)
Felix Kling