custom forms django code example
Example 1: passing user instance django form submission
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
Example 2: django model form
class YourForm(ModelForm):
class Meta:
model = YourModel
fields = ['pub_date', 'headline', 'content', 'reporter']
Example 3: django forms
<div class="fieldWrapper">
{{ form.subject.errors }}
{{ form.subject.label_tag }}
{{ form.subject }}
</div>