On Tue, Oct 18, 2011 at 8:22 PM, Jack Morgan <jackofseat...@gmail.com>wrote:

> I've got 2 tables that are related to each other. Orders and History.
> Inside the History table is the 'status' column. Like so..
>
> class Orders(models.Model):
>   'order info'
>
> class History(models.Model):
>     timestamp = models.DateTimeField(auto_add_now = True)
>     order = models.ForeignKey(Orders)
>     user = models.ForeignKey(User)
>     comment = models.TextField()
>     status = models.CharField(max_length = 20)
>
>
> I'm storing the status in the History table right now because I need to
> keep track of who is moving the orders along.  However, I need to do a
> lookup on orders based on their current(most recent) status.  For
> simplicities purpose it seems a good idea would be to just put a status
> field in the Orders table and update as the Order advances through the
> stages. However, that creates duplicate data, which my client has expressed
> an extreme hatred for.
>
> What It's like to be able to do is something like:
> o = Orders.filter(status = 'new')
>
> I'm not entirely sure how or when relationship managers are brought in, so
> I was thinking something like this in the Orders model:
> status = self.history_set.values('status').order_by('-id')[0]['status']
>
> But that wouldn't let me do a lookup by state.
>
> What's a good Django way to handle this issue?
>

Having the status field in the Order's column is the elegant way to do it.
History model,  should be like a revision-holder; mainly used for auditing.

-V
http://blizzardzblogs.blogspot.com/

-- 
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.

Reply via email to