Hi, yes i was approaching it very wrong, but figured it out. Here is a little test which i got to work with the help of some IRC django people! (Thanks).
I didnt know that django would also send all the related items from the intermediate table to the template. Very nice! I guess I should do some filtering thou as this could be a lot of data.. Using my "news", "imagegroup", "images" setup, this is how i get to the "images" data from the news object. Yes News as a name would be better but than admin made Newss out of it ;), I forgot that you can define the plural some where in the model. This gets the 1st result:<br /> {{ new.imagegroup.all.0.image.caption }} {% if new.imagegroup.all.0 %} <br />This has images {% else %} <br />This has NO images {% endif %} <br /> This gets all results: <br /> {% for newsitem in new.imagegroup.all %} <p> {{ newsitem.createdate }} <br /> {{ newsitem.position }} <br /> {{ newsitem.image.caption }} <br /> {{ newsitem.image.get_imagefile_url }} </p> {% endfor %} On Apr 2, 10:17 am, Atilla <[EMAIL PROTECTED]> wrote: > On 30/03/07, oliver <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > I am starting out with django and python, don't have much experience > > in either. I have managed to create a few "simple" website with django > > and really enjoy working with it. > > > But I am a bit stuck on my latest project. I am using a M2M relation > > via an intermediary table. > > >http://dpaste.com/hold/7651/ I put all the code in there .. > > > I have a Image model, a ImageGroup (intermediate table) model and a > > News (New) model. > > New(s) has a: > > imagecollection = models.ManyToManyField(ImageGroup...) > > > and ImageGroup holds: > > Position (for sorting) > > and a ForgeignKey to Image > > > Image holds: > > Caption and the path to the image file. > > > I made a simple inclusion tag to get my News objects and send them to > > my template. > > But I am stuck on how do I get to the image data in my template? More > > specific for this example I only need the 1st image, later on I will > > need all related images but I hope I will understand how to do it once > > I get to that stage. > > > I guess I need something in the inclusion_tag to get me the related > > images in the order of the intermediate table "position" field? > > > I tried this but django complains about "self" (global name 'self' is > > not defined) > > images = ImageGroup.objects.filter( new = > > self.id ).order_by( 'position' )[:1] > > That can't work. I guess what you're trying to do can be accomplished > with ImageGroup.objects.select_related().latest(). Or any other > filter you require, instead of the latest() shortcut. > > See how to read out the list of related fields in the django docs, and > also not that you can do filter() on fields of the related models as > well, for example Image.objsects.filter(imagegroup__new__islive=True). > > Also - "News" has no singular form,"New" is a weird class name to use, > isn't it ? :) > > > I read the docs and found examples in this group but I can't get my > > head around it how it works on my model layout. > > > any help will be greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---