class Hardware(models.Model):
blah = models.CharField()
...
#called every time the model instance is saved
def save():
#if you want many hardware history records for a piece of
hardware
history = HardwareHistory.create(hardware=self, ...)
#if you only want 1 hardware history record for update each
time (not good relational structure)
history = HardwareHistory.get_or_create(hardware=self, ...)
class HardwareHistory(models.Model):
hardware = models.ForeignKey(Hardware)
hotani wrote:
> I am attempting to avoid writing a custom admin page. There are at
> most two people that will be updating the database, and this seems
> like a great job for the django admin area.
>
> However, for this to work I need a way to update a 2nd model (a
> history table) when another model is updated. Is this possible? I was
> hoping there would be a way to do it via model method, but have not
> found anything yet.
>
> Example:
>
> Model 1 (hardware items):
> id
> date_modified
> location
> last_action
> ...many other fields...
>
> Model 2 (history table):
> hardware_id
> location
> action
> date
>
> The idea is to be able to look up a hardware item, then view its
> history: what locations it has been to, dates and actions. I can in
> theory have them update the history table every time an items status
> changes, but I don't think that is a very friendly solution. It would
> be nice to update the history table every time a hardware item was
> changed. Better yet, every time a specific field in the hardware table
> changed (such as location or last action).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---