我是这种语言的新手,并尝试从我创建的2个模型中创建一个表单models.pyfrom locpick.field import LocationFieldfrom django.db import modelsfrom django.db.models import permalinkfrom django.contrib import adminfrom PIL import Imagefrom time import timedef 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对象的错误我要去哪里错了
添加回答
举报
0/150
提交
取消