Return a model of formset by id
337827
public function getModelByPrimaryKey($id)
    {
        foreach($this->models as $model)
        {
            $primaryKey = $model->getKeyName();
            if($model->$primaryKey == $id)
                return $model;
        }
    }
235661
def save_formset(self, request, form, formset, change):
        
        formset.save()

        for form in formset.forms:
            if hasattr(form, 'nested_formsets') and form not in formset.deleted_forms:
                for nested_formset in form.nested_formsets:
                    self.save_formset(request, form, nested_formset, change)
1325524
def all_valid(formsets):
    """"""
    valid = True
    for formset in formsets:
        if not formset.is_valid():
            valid = False
    return valid
218146
def recordset(method):
        """"""
        def wrapper(self, *args, **kwargs):
            if self.__records__ is None:
                raise ValidationError(
                    'There are no records in the set.',
                )
            return method(self, *args, **kwargs)
        return Api.model(wrapper)
483733
def get_formset_class(self, form, name):
        
        if self.formset_class is not None:
            return self.formset_class
        formset_class = inlineformset_factory(
            self.get_parent_model(form, name),
            self.get_model(form, name),
            **self.formset_factory_kwargs)
        return formset_class
104767
def get_form(self, key, form_class=None):
        
        if form_class is None:
            form_class = self.get_form_class(key)
        return form_class(**self.get_form_kwargs(key))
667332
def get_formset(self, request, obj=None, **kwargs):
        
        if obj is not None and self.model.objects.filter(user=obj).count():
            return super(StaffMemberAdmin, self).get_formset(
                request,
                obj,
                **kwargs
            )

        defaults = {
            "exclude": None,
            "extra": 0,
            "max_num": 0,
        }
        return inlineformset_factory(self.parent_model, self.model, **defaults)
1031703
def get_formset(self, request, obj=None, **kwargs):
        
        def _placeholder_initial(p):
            # p.as_dict() returns allowed_plugins too for the client-side API.
            return {
                'slot': p.slot,
                'title': p.title,
                'role': p.role,
            }

        # Note this method is called twice, the second time in get_fieldsets() as `get_formset(request).form`
        initial = []
        if request.method == "GET":
            placeholder_admin = self._get_parent_modeladmin()

            # Grab the initial data from the parent PlaceholderEditorBaseMixin
            data = placeholder_admin.get_placeholder_data(request, obj)
            initial = [_placeholder_initial(d) for d in data]

            # Order initial properly,

        # Inject as default parameter to the constructor
        # This is the BaseExtendedGenericInlineFormSet constructor
        FormSetClass = super(PlaceholderEditorInline, self).get_formset(request, obj, **kwargs)
        FormSetClass.__init__ = curry(FormSetClass.__init__, initial=initial)
        return FormSetClass
857042
def process_form(self, instance, field, form, empty_marker=None,
                     emptyReturnsMarker=False, validating=True):
        
        service_uids = form.get("uids", [])
        return service_uids, {}
1330339
def _get_form(self, config_name, only_required=False):
        """"""
        if getattr(self, config_name, None):
            return import_object_by_string(getattr(self, config_name))

        def use_field(field):
            if not only_required:
                return True
            return field.default == NOT_PROVIDED

        return modelform_factory(self.model, fields=[f.name for f in self.model.get_fields() if use_field(f)])
154621
function(model, options) {
      if (!(model instanceof Parse.Object)) {
        var attrs = model;
        options.collection = this;
        model = new this.model(attrs, options);
        if (!model._validate(model.attributes, options)) {
          model = false;
        }
      } else if (!model.collection) {
        model.collection = this;
      }
      return model;
    }
1233752
def initialize_form(self, instance, model, data=None, extra=None):
        
        model_fields = self.get_fields_from_model(model, self._filter_fields)

        forms = []
        if instance:
            for field_data in instance.list_fields():
                forms.append(
                    AdvancedFilterQueryForm._parse_query_dict(
                        field_data, model))

        formset = AFQFormSetNoExtra if not extra else AFQFormSet
        self.fields_formset = formset(
            data=data,
            initial=forms or None,
            model_fields=model_fields
        )
982375
def get_by_model(self, model):
        """"""
        content_type = ContentType.objects.get_for_model(model)
        return self.filter(content_type=content_type)
424939
def badge_form(model):
    ''''''
    class BadgeForm(ModelForm):
        model_class = Badge

        kind = fields.RadioField(
            _('Kind'), [validators.DataRequired()],
            choices=model.__badges__.items(),
            description=_('Kind of badge (certified, etc)'))

    return BadgeForm
1167389
def get_composite_field_value(self, name):
        
        field = self.composite_fields[name]
        if hasattr(field, 'get_form'):
            return self.forms[name]
        if hasattr(field, 'get_formset'):
            return self.formsets[name]
163172
def get(cls, id_):
        """"""
        with db.session.no_autoflush:
            query = cls.dbmodel.query.filter_by(id=id_)
            try:
                model = query.one()
            except NoResultFound:
                raise WorkflowsMissingObject("No object for for id {0}".format(
                    id_
                ))
            return cls(model)
592268
def all_valid_with_nesting(self, formsets):
        ""
        if not all_valid(formsets):
            return False

        for formset in formsets:
            if not formset.is_bound:
                pass
            for form in formset:
                if hasattr(form, 'nested_formsets'):
                    if not self.all_valid_with_nesting(form.nested_formsets):
                        return False

                    #TODO - find out why this breaks when extra = 1 and just adding new item with no sub items
                    if (not hasattr(form, 'cleaned_data') or not form.cleaned_data) and self.formset_has_nested_data(form.nested_formsets):
                        form._errors["__all__"] = form.error_class(["Parent object must be created when creating nested inlines."])
                        return False
        return True