Created
June 12, 2018 06:03
-
-
Save taranjeet/c503278293ea77f77fb2e0f88f8d9fc7 to your computer and use it in GitHub Desktop.
Django Library: Author Formset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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