On 8/12/06, Vizcayno <[EMAIL PROTECTED]> wrote:
> For material-1 I know that the price $13.59 is valid from 2006-05-04 to
> the infinite, until a new price is established for this material.

..snip...

>  If a record has the field date/time="2999-12-31 23:59:59" it means it
> is in effect, but if it contains "2006-08-10 10.00:01", for example, it
> is an expired record however I must keep it for historical reasons. For
> example

This sounds more like a database design issue; what you want to say is
not "this price is valid for eternity", but rather "this is the
current price".

One better way to go about it might look like this:

class Material(models.Model):
    name = models.CharField()

    def _get_current_price(self):
        return self.price_set.filter(active=True).latest()

    current_price = property(_get_current_price)

class Price(models.Model):
    material = models.ForeignKey(Material)
    price = models.FloatField(max_digits=5, decimal_places=2)
    is_active = models.BooleanField()
    effective_from = models.DateTimeField()
    effective_to = models.DateTimeField(null=True, blank=True)

    class Meta:
        get_latest_by = 'effective_from'

A little validation in the save() method for Price (or maybe even a
custom validator) to ensure that only one "active" price exists for a
given Material at any time, and you're good to go; given an instance
of Material, say in a variable 'm', you can then do
'm.current_price.price' to get the currently effective price for the
material, and 'm.price_set.all()' to get the historical list of all
prices (or 'm.price_set.filter(active=False)' to get only the previous
prices).

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

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

Reply via email to