Django Inline Formsets using custom form

前端 未结 2 1191
春和景丽
春和景丽 2021-02-19 05:28

I am using inline formsets.

My model:

class Author(models.Model):
    description = models.CharField(max_length=100)

class Book(models.Model):
    autho         


        
2条回答
  •  清酒与你
    2021-02-19 06:23

    Try:

    class BookForm(ModelForm):
        class Meta:
            model = Book
            widgets = {
                'details': Textarea(attrs={'cols': 40, 'rows': 4}),
            }
    
    
    InlineFormSet = inlineformset_factory(Author, Book, form=BookForm)
    

    Update by Wtower

    This is great. Specifically for widgets, as of Django 1.6 there is a widgets parameter for inlineformset_factory

    Sounds like you can now call

    inlineformset_factory(Author, Book, widgets={'details': Textarea(attrs={'cols': 40}))
    

提交回复
热议问题