我想要检索特定用户的所有图像。我需要帮助。
这是我的模特
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}
这是我的urls.py
urlpatterns = patterns('gallery.views',
url(r'^(?P<event_id>\d+)/images/$', 'eventimage'),
)
这是我的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,
})
但这不会显示特定事件图像的图像。需要帮助。
答案 0 :(得分:1)
您的查询不正确,您可以使用
进行查询 e_piclist = image_archive.objects.filter(event_id = event_id)
。
另外,请尝试使用.filter()
代替.get()
。
答案 1 :(得分: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})