一个应用程序上的几个图像

时间:2015-08-26 06:22:09

标签: python django django-templates django-views

我尝试在django 1.8上创建新闻应用程序。我想在一个新闻中我可以从后端添加几个图像。所以这是我的models.py 来自django.db导入模型

class Category(models.Model):

        category = models.CharField('Category', max_length=255)
        slug = models.CharField(max_length=255)

        def __unicode__(self):
                return self.category

class Images(models.Model):

        image = models.ImageField('Images', upload_to='media/img/news')
        news = models.ForeignKey('News', blank=True, null=True)

class News(models.Model):

        title = models.CharField(max_length=255)
        category = models.ForeignKey('Category', blank=True, null=True)
        teazer_image = models.ImageField(upload_to='media/img/news', blank=True)
        pub_date = models.DateField(null=True)
        slug = models.CharField(max_length=255)
        short_content = models.TextField(max_length=2000, blank=True)
        content = models.TextField(max_length=10000)
        image = models.ForeignKey('Images', blank=True, null=True)
        meta = models.CharField(max_length=255, blank=True)
        description = models.TextField(max_length=10000, blank=True)

        def __unicode__(self):
                return self.title

Admin.py

from django.contrib import admin
from news.models import News, Category, Images
from django.shortcuts import get_object_or_404

class ImagesInline(admin.TabularInline):
        model = Images

class NewsAdmin(admin.ModelAdmin):
        inlines = [
                ImagesInline,
        ]

admin.site.register(News, NewsAdmin)
admin.site.register(Images)
admin.site.register(Category)

但我不明白如何创建视图和模板。你能帮帮我吗?

0 个答案:

没有答案