Skip to content

Instantly share code, notes, and snippets.

@taranjeet
Created June 12, 2018 06:03
Show Gist options
  • Save taranjeet/c503278293ea77f77fb2e0f88f8d9fc7 to your computer and use it in GitHub Desktop.
Save taranjeet/c503278293ea77f77fb2e0f88f8d9fc7 to your computer and use it in GitHub Desktop.
Django Library: Author Formset
# forms.py :: part 1
from django import forms
from django.forms import modelformset_factory
from .models import Book, Author
class BookModelForm(forms.ModelForm):
class Meta:
model = Book
fields = ('name', )
labels = {
'name': 'Book Name'
}
widgets = {
'name': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter Book Name here'
}
)
}
AuthorFormset = modelformset_factory(
Author,
fields=('name', ),
extra=1,
widgets={
'name': forms.TextInput(
attrs={
'class': 'form-control',
'placeholder': 'Enter Author Name here'
}
)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment