1. What is your code for doing the filters? If you want to start with physical drives it would be something like:
RaidPhysicalDrive.objects.filter(in_array__in_storage__in_system__id=<id>) 2. In your template you've referenced pd.in_array_id, but don't you just want pd.in_array if you're wanting to follow the FK to get RaidArray fields, e.g., <td>{{ pd.in_array.in_storage.in_system.name<http://pd.in_array_id.storage.in_system.name/>}}</td> On Mon, Aug 16, 2010 at 8:04 PM, Cindy <tit...@gmail.com> wrote: > I'm having some trouble constructing a filter that's intended to work > across multiple tables with selected fields. Here's a simplified > outline of my models: > > class System(models.Model): > name = models.CharField(max_length=16) > domain = models.CharField(max_length=255, default='example.com') > > class RaidStorage(models.Model): > in_system = models.ForeignKey(System) > name = models.CharField(max_length=25) > > class RaidArray(models.Model): > in_storage = models.ForeignKey(RaidStorage) > name = models.CharField(max_length=25) > > class RaidPhysicalDrive(models.Model): > in_array = models.ForeignKey(RaidArray) > name = models.CharField(max_length=25) > size = models.IntegerField(null=True, blank=True) > serial = models.CharField(max_length=25) > model = models.CharField(max_length=25) > > Now, given a system id, I want to list all the physical drives from it > along with info from the related tables. I would like something like > > select System.name, RaidStorage.name, RaidArray.name, > RaidPhysicalDrive.name, RaidPhysicalDrive.serial, > RaidPhysicalDrive.model from System, RaidStorage, RaidArray, > RaidPhysicalDrive where RaidPhysicalDrive.in_array=RaidAarray.id and > RaidArray.in_storaage = RaidStorage.id and RaidStorage.in_system=id > (etc) > > I'm having a good deal of trouble coming up with the filters for > this. I'm thinking that .values() and possibly .select_related() are > key here, but so far I've failed at putting together anything that > gives me the results I want (a list of physical drives associated with > the selected system). The filter examples through the tutorials and > such seem to all assume select *, and there's very little on dealing > with grouping selective fields from multiple tables that I've found. > > Part of the issue might be in the template as well; If I cheat and > send it the correct list, I can't access part of the information I > want: > > {% for pd in pd_list %} > <tr> > <td>{{ pd.in_array_id.storage.in_system.name }}</td> > <td>{{ pd.in_array_id.in_storage.name }}</td> > <td>{{ pd.in_array_id.name }}</td> > <td>{{ pd.name }}</td> > <td>{{ pd.serial }}</td> > <td>{{ pd.model }}</td> > </tr> > {% endfor %} > > results in the first three columns of the table being empty... > templates don't seem to "follow" back the way they do in views.py, > etc. So I'm sure I need to create a dictionary or list from the > original views.py def to pass to the template but as I say, I'm not > sure of how to use .values or .select_related (or whatever else item > I'm overlooking). > > I did search through the group a bit, but didn't find anything > directly helpful. > > Thanks! > --Cindy > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.