I've got to keep an inventory of servers and their memory modules & drives. I've created three tables. I want to be able to retrieve all information about the server, including memory and drive information, and display it in one page.
class Server(models.Model):
Name = models.CharField(max_length=25)
ServiceTag = models.CharField(primary_key=True,max_length=12) #Uniquely identifies each server
def __unicode__(self):
return u'%s %s ' % (self.Name, self.ServiceTag)
class MemoryModule(models.Model):
Manufacturer = models.CharField(max_length=15)
Size = models.CharField(max_length=15)
server = models.ForeignKey(Server, max_length=12)
mems = MemoryManager()
def __unicode__(self):
return u'%s %s' % (self.Manufacturer, self.Size)
class Drive(models.Model):
Manufacturer = models.CharField(max_length=15)
Size = models.CharField(max_length=15)
server = models.ForeignKey(Server, max_length=12)
drvs = DriveManager()
def __unicode__(self):
return u'%s %s %s %s %s' % (self.Manufacturer, self.Size)
I was considering adding the following "managers":
class MemoryManager(models.Manager):
def get_query_set(self):
return super(MemoryManager, self).get_query_set().filter(server='CC98361')
class DriveManager(models.Manager):
def get_query_set(self):
return super(DriveManager, self).get_query_set().filter(server='CC98361')
...so that the following would generate memorymodules & drives associated with the service tag value:
MemoryModule.mems.all()
Drive.drvs.all()
a. Is this an accurate approach b. if so, how would I display "MemoryModule.mems.all() and Drive.drvs.all() in a template?