<s> from __future__ import unicode_literals <EOL> from django import forms <EOL> from django . forms . models import BaseModelFormSet <EOL> from django . forms . models import modelformset_factory <EOL> from machina . conf import settings as machina_settings <EOL> from machina . core . db . models import get_model <EOL> Attachment = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class AttachmentForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Attachment <EOL> fields = [ '<STR_LIT:file>' , '<STR_LIT>' , ] <EOL> class BaseAttachmentFormset ( BaseModelFormSet ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . post = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( BaseAttachmentFormset , self ) . __init__ ( * args , ** kwargs ) <EOL> def save ( self , commit = True , ** kwargs ) : <EOL> if self . post : <EOL> for form in self . forms : <EOL> form . instance . post = self . post <EOL> super ( BaseAttachmentFormset , self ) . save ( commit ) <EOL> AttachmentFormset = modelformset_factory ( <EOL> Attachment , AttachmentForm , <EOL> formset = BaseAttachmentFormset , <EOL> can_delete = True , extra = <NUM_LIT:1> , <EOL> max_num = machina_settings . ATTACHMENT_MAX_FILES_PER_POST , <EOL> validate_max = True ) </s>
