나는 두 가지 모델을 가지고,이 책과 저자이며, 내가 책 및 액세스 저자의 CreateView을 만들려면 나는 책 모델장고 ManyToMany CreateView 필드
class Author(models.Model):
name = models.CharField(verbose_name='name', max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return unicode(self.name)
class Book(models.Model):
title = models.CharField(verbose_name='title', max_length=50)
authors = models.ManyToManyField(Author) # Many to many
created_at = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return unicode(self.title)
내부 ManyToMany 필드를 추가 난 그냥 수 이
class BookCreateView(CreateView):
model = Book
template_name = "books/book_create.html"
fields = ['title', 'authors']
하지만 난 저자 모델에서 CreateView을 만들고 그 안에 필드 이름 책을를 추가 할 것입니다 물어보고 싶은 무언가 같이 코드를 추가합니다. 나는이
class AuthorCreateView(CreateView):
model = Author
template_name = "books/author_create.html"
fields = ['name', 'books']
처럼 코딩 시도하고 오류 "알 수없는 필드 (들) (책) 저자에 대해 지정"을 보여줍니다.
도움이 나에게 주인, 나는 당신이 AuthorCreateView
분야에서 그를 추가 할 수 없습니다, 필드가 books
이름이없는 장고에 Author
모델 이후
감사합니다 :)