I’m playing around trying to move an Excel timesheet we use into Django. I have the very basics down but am missing one thing. I have most of the low level models working:
class Employee(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Client(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Location(models.Model):
client = models.ForeignKey(Client)
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
This part works great, I can add a “Client” and set their multiple locations. Now I am trying to tie all of that to another model.
Class WorkEvent(models.Model):
description = models.CharField(max_length=100)
startTime = models.DateTimeField('Start Time')
Here I need to tie an instance of WorkEvent to an instance of “Employee” and and instance of “Location”. Many “WorkEvent”s can point to the same “Employee” or “Location”, but each “WorkEvent” can only have one of each of those. I’m not sure how to set up this relationship.
If I understand what you’re looking for, this could work ( I haven’t actually tried it, there could be syntax or other issues):