oxvoxic
oxvoxic

Reputation: 31

Django views.py code for parameter

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.

Upvotes: 0

Views: 66

Answers (2)

Burhan Khalid
Burhan Khalid

Reputation: 174614

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})   

Upvotes: 0

Rohan
Rohan

Reputation: 53316

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().

Upvotes: 1

Related Questions