我是这种语言的新手,并尝试从我创建的2个模型中创建一个表单
models.py
from locpick.field import LocationField
from django.db import models
from django.db.models import permalink
from django.contrib import admin
from PIL import Image
from time import time
def get_upload_file_name(instance, filename):
return "photo/%s_%s" % (str(time()).replace('.','_'), filename)
class Journey(models.Model):
name = models.CharField(max_length=250)
location = LocationField()
description = models.TextField()
date = models.DateTimeField()
class Meta:
ordering = ['name']
def __unicode__(self):
return self.name
@permalink
def get_absolute_url(self):
return ('item_detail', None, {'object_id': self.id})
class Photo(models.Model):
item = models.ForeignKey(Journey)
upload = models.ImageField(upload_to=get_upload_file_name)
class Meta:
ordering = ['title']
def __unicode__(self):
return self.title
@permalink
def get_absolute_url(self):
return ('photo_detail', None, {'object_id': self.id})
class PhotoInline(admin.StackedInline):
model = Photo
class JourneyAdmin(admin.ModelAdmin):
inlines = [PhotoInline]
list_display = ('name', 'location','description')
admin.site.register(Journey, JourneyAdmin)
表格
from django import forms
from models import Journey, Photo
class JourneyForm(forms.ModelForm):
class Meta:
model = Journey
fields = ('name','location','description','date')
class PhotoForm(forms.ModelForm):
class Meta:
model = Photo
exclude = ('item')
views.py
from django.template import loader, Context
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.http import HttpResponse
from locpick.models import Journey , Photo
from forms import JourneyForm, PhotoForm
from django.core.context_processors import csrf
我收到创建ddidnt返回HttpResponse对象的错误
我要去哪里错了
相关分类