On Tue, Jul 12, 2011 at 4:32 AM, garagefan <monkeygar...@gmail.com> wrote: > simply put, here's my code > > class ContentBlock(Orderable, Displayable): > location = models.ManyToManyField(ContentBlockLocation, blank=True, > null=True, help_text="list of locations to display content block") > page = models.ManyToManyField(Page, blank=True, null=True, > help_text="list of pages to display content block") > height = models.IntegerField(blank=True, null=True) > width = models.IntegerField(blank=True, null=True) > > def __unicode__(self): > return self.title > > > class StaticContent(Displayable, RichText): > content_block = models.ForeignKey(ContentBlock, blank=True, > null=True) > > class StaticContent2(Displayable, RichText): > content_block = models.ForeignKey(ContentBlock, blank=True, > null=True) > > putting together a template tag that will return all the items > associated with a given ContentBlock, but i would like to do so > without knowing upfront all of the classes that have a foreign key to > ContentBlock as i'll want to be able to add more content types at any > time >
Hi. I think something like this is what you need: obj = ContentBlock(pk=1) for related in obj._meta.get_all_related_objects(): model = related.model field = related.field if related.parent_model == ContentBlock: for rel_object in model.objects.filter(**{'%s' % (field.name): obj}): #rel_object is what you want -- Marc -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.