Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • Django modelformset_factory便利

    Django は複数のフォームのデータを同時に扱えるために、FormSetsというものを用意しているんですけど、実は、ModelFormのFormSetでも使える。クエリーの結果のデータのModelFormを一個一個、一つのページに出すにはこんなコードを書ける。

    from django.forms.models import modelformset_factory
    
    formset = modelformset_factory(
        MyModel,
        fields=('status','content'),
        extra=0,
    )(queryset=MyModel.objects.filter(status=1))
    

    便利

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - Django modelformset_factory便利