0

こんにちは皆さん、私はこれに苦労しています。グーグルがこの1つのハードコアを検索しました。

各アルバムが出力され、画面オーバーレイをクリックすると画像ギャラリーが表示される画像ギャラリーを開発しています。ギャラリーに各画像を表示するためのJavaScriptでのハードワークが行われているため、次の式で指定された画像パスのみが必要です。

{{ images.content }}

以下は、djangoプロジェクトで使用しているファイルです。

これに関するヘルプは素晴らしいでしょう。

manage.py

from django.db import models

PHOTO_PATH = 'media_gallery'

class Gallerys(models.Model):
    title = models.CharField(max_length=30, help_text='Title of the image maximum 30 characters.')
    slug = models.SlugField(unique_for_date='date', help_text='This is automatic, used in the URL.')
    date = models.DateTimeField()

    class Meta:
        verbose_name_plural = "Image Galleries"
        ordering = ('-date',)

    def __unicode__(self):
        return self.title

class Images(models.Model):
    title = models.CharField(max_length=30, help_text='Title of the image maximum 30 characters.')
    content = models.FileField(upload_to=PHOTO_PATH,blank=False, help_text='Ensure the image size is small and it\'s aspect ratio is 16:9.')
    gallery = models.ManyToManyField(Gallerys)
    date = models.DateTimeField()

    class Meta:
        verbose_name_plural = "Images"
        ordering = ('-date',)

    def __unicode__(self):
        return self.title

import models
from django.contrib import admin

class ImagesAdmin(admin.ModelAdmin):
    list_display = ('title', 'date')

class GallerysAdmin(admin.ModelAdmin):
    list_display = ('title', 'date', 'slug')

admin.site.register(models.Images, ImagesAdmin)
admin.site.register(models.Gallerys,GallerysAdmin)

views.py

from django.http import HttpResponse
from notices.models import Notices
from django.shortcuts import get_object_or_404
from django.shortcuts import render_to_response
from gallery.models import *
from navigation.models import *

# when the galleries page is requested, all image galleries are listed by date created with the latest first,
# each gallery displayed contains a javascript tag containing an index of images separated by ';'
def galleries(request):
    gallery = Gallerys.objects.all()
    images = Images.objects.all()

    return render_to_response('galleries.html', {'Galleries': gallery, 'Images': images})

galleries.html

        {% for galleries in Galleries %}
            <h1>{{ galleries.title }}</h1>
            {% for images in galleries.gallery.all %}
                <h2>{{ images.content }}</h2>
            {% empty %}
                none
            {% endfor %}
        {% endfor %}

繰り返すとき:

<h2>{{ images.content }}</h2>

何も得られません、どこが間違っているのですか?

ありがとう!

4

1 に答える 1

1

galleryオブジェクトで呼び出される属性はありませんGalleries

デフォルトのリバースm2mアクセサーを使用するimages_set

{% for images in galleries.images_set.all %}

{% endfor %}
于 2013-01-16T00:37:20.483 に答える