Form & ModelForm
.order_by()
.order_by()articles = Article.objects.order_by('-pk')ModelForm
Defining ModelForm
from django import forms
from .models import Article
class ArticleForm(forms.ModelForm):
title = forms.CharField(
max_length=100,
label='Title',
help_text='Your title must be no more than 100 characters in length',
widget=forms.TextInput(
attrs={
'class':'my_input',
'placeholder': "What's on your mind?"
}
)
)
content = forms.CharField(
label='Content',
help_text='Jot down random musings and thoughts',
widget=forms.Textarea(
attrs={
'row':5,
'col':50,
}
)
)
class Meta:
model = Article
# Include all fields
fields = '__all__'Using ModelForm in View
ModelForm in ViewConditional processing with request.resolver_match.url_name
request.resolver_match.url_nameOutput using loop or bootstrap4
loop or bootstrap4Looping over the form's fields
Form rendering options
Using Django Bootstrap
Git
Last updated