How can I get a textarea from model+ModelForm?

后端 未结 2 789
北恋
北恋 2021-02-14 08:52

models.py=>

from django.db import models
from django.forms import ModelForm
from datetime import date
import datetime
from django import forms
from django.forms          


        
相关标签:
2条回答
  • 2021-02-14 09:45

    I think this section in the documentation should be useful to solve the problem.

    from django.forms import ModelForm, Textarea
    
    class PostModelForm(ModelForm):
        class Meta:
            model = Post
            widgets = {
                'content': Textarea(attrs={'cols': 80, 'rows': 20}),
            }
    
    0 讨论(0)
  • 2021-02-14 09:52

    Alternative to jcollardo's solution (same result, different syntax):

    from django import forms
    
    class PostModelForm(forms.ModelForm):
        content = forms.CharField(widget=forms.Textarea)
        class Meta:
            model = Post
    
    0 讨论(0)
提交回复
热议问题