class Peg(models.Model):
    history = OneToManyField(class=PegEntry)

class Hole(models.Model):
    peg = models.ForeignKey(class=Peg, blank=True, null=True)

class PegEntry(models.Model):
    hole = models.ForeignKey(class=Hole)
    start = models.DateTimeField()
    end = models.DateTimeField()

I think that's the basic model schema. To find empty holes, you'd write

Hole.objects.filter(peg=None)

To get a list of all pegs that have been in a given hole, use

[peg_entry.peg for peg_entry in
PegEntry.objects.filter(hole=given_hole)]

On Thu, 2006-10-26 at 21:42 -0700, PirahnaBreaks wrote:
> I'm a recovering PHP developer and I'm looking at using Django for my
> next project - I know how to accomplish the following in PHP (well,
> technically it's mostly accomplished in SQL...) but I'd like to know
> how difficult it would be to handle this in Django:
> 
> I'm trying to create a model for a certain type of physical object -
> we'll say, a (theoretical) peg.  I also have a model for a grid of
> holes.  A given peg may occupy any hole, but only one at a time.  For
> my particular case, I have a pressing need to know what holes a given
> peg has occupied, and *when*.  It would also be nice to be able to pull
> up a list of available holes, or get a complete peg occupancy history
> for a given hole :)
> 
> If I was creating a SQL schema by hand, I would create a join table
> with something like these columns:
> peg_id
> hole_id
> occupied_start_time
> occupied_end_time
> 
> And then write all the queries by hand.  I'd like to know the
> "cleanest" way to work with Django on this - it's a wonderful
> framework, and I'd like the opportunity to learn/switch to Python, but
> if I have to reinvent the wheel, I'm a lot more used to doing that
> writing a PHP app.  Does anyone have any ideas or sample code I could
> look at?
> 
> Thanks!
> 
> 
> > 


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to