0

I want to retrieve all image of a particular user. I need help.

here is my model

class image_archive(models.Model):
 image_id            = models.AutoField(primary_key=True)
 event_id            = models.ForeignKey(event_archive,db_column='event_id')
 image_url           = models.CharField(max_length=45)
 screenshot_url      = models.URLField(max_length=200)
 image_title         = models.CharField(max_length=45)
 date_submitted      = models.DateTimeField()
 image_description   = models.TextField() 
 original_image      = models.ImageField(upload_to=file_upload_path)
 formatted_image     = ImageSpecField([FormatImage()],image_field='original_image', format='JPEG',
                                     options={'quality': 90})
 thumbnail_image     = ImageSpecField([Adjust(contrast=1.2, sharpness=1.1),
                                      ResizeToFill(50, 50)], image_field='original_image',
                                     format='JPEG', options={'quality': 90}

here is my urls.py

urlpatterns = patterns('gallery.views',   
url(r'^(?P<event_id>\d+)/images/$', 'eventimage'),             

)

here is my views.py

def eventimage(request,event_id):
e_piclist  =  image_archive.objects.get(id = event_id)  
return render_to_response('gallery/image.html', 
 {  
    'e_piclist' : e_piclist,  
    'image_archive':image_archive,
 })   

But this doest not show the images of a particular event's image. Need help.

2 Answers 2

1

Your query is incorrect, you can query it using

e_piclist = image_archive.objects.filter(event_id = event_id).

Also, try to use .filter() instead of .get().

Sign up to request clarification or add additional context in comments.

Comments

0
from django.shortcuts import render, get_object_or_404

def eventimage(request,event_id):

    my_event = get_object_or_404(Event, pk=event_id)
    image_list = my_event.image_archive_set.all()

    return render(request,'gallery/image.html',{'e_piclist':image_list})   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.