错误:
'list' object has no attribute '_meta'
forms.py:
from django.db import models
from django.forms import ModelForm
from django import forms
class Blog(models.Model):
blog_id = models.CharField(max_length=100)
class TumblrForm(ModelForm):
class Meta:
model = Blog
fields = ('blog_id',)
widgets = {
'blog_id':forms.RadioSelect(),
}
表单创建:
form = TumblrForm(instance=blogs_id) #blogs_id is a list of blog urls
我哪里错了?
答案 0 :(得分:1)
ModelForm
编辑一个实例。您无法将其传递给网址列表。它需要一个Blog
的实例。
TumblrForm(instance=Blog.objects.get(pk=1))
如果你想编辑多个ModelForms,你需要查看django的FormSet
。