Hi all,
using Django 1.3 (soon 1.4), we use models like these:
class Staff(models.Model):
name = models.CharField(max_length=80)
class Period(models.Model):
staff = models.ForeignKey(Staff)
begin = models.DateField()
end = models.DateField(editable=False) # see below
# The actual data that describes this period,
# e.g. department, salary, ...
department = models.CharField(max_length=60)
class Meta:
ordering = ['begin']
There are normally several Period instances for each staff member, and
the set of periods for one staff member form a chronological sequence:
A period begins at the day given in 'begin'.
It ends at the day before the *next* period begins.
Thus, in our original design, there was no field 'end' in the Period
model, because logically, it was not needed. (The last period is
"open-ended".)
However, we found that many queries are very difficult to build without
the 'end' (such as "Find all staff members in department X on November
1st"), and thus are planning to add it as shown above.
'end' should always be computed automatically as the day before the
begin of the next period, but I don't know where this is best
implemented in the admin interface:
class PeriodInline(admin.TabularInline):
model = Period
class StaffAdmin(admin.ModelAdmin):
inlines = [ PeriodInline ]
(Note that it is not enough to consider the Period that changed --
rather, it is the 'end' in *another* period (the one "before" it) that
must be modified and saved, too.)
What is the proper hook or where the best place to do this?
Many thanks in advance, and best regards,
Carsten
--
Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
Learn more at http://www.cafu.de
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.