python类inlineformset_factory()的实例源码

set.py 文件源码 项目:wger-lycan-clan 作者: andela 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_formset(request, exercise_pk, reps=Set.DEFAULT_SETS):
    '''
    Returns a formset. This is then rendered inside the new set template
    '''
    exercise = Exercise.objects.get(pk=exercise_pk)
    SettingFormSet = inlineformset_factory(Set,
                                           Setting,
                                           can_delete=False,
                                           extra=int(reps),
                                           fields=SETTING_FORMSET_FIELDS)
    formset = SettingFormSet(queryset=Setting.objects.none(),
                             prefix='exercise{0}'.format(exercise_pk))

    return render(request,
                  "set/formset.html",
                  {'formset': formset,
                   'exercise': exercise})
views.py 文件源码 项目:Sermul 作者: CHOQUERC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def CrearCobro(request,empleado_slug=None,cliente_slug=None):
    cliente = Cliente.objects.get(slug=cliente_slug)
    cobro_form = CobroForm(request.POST or None)
    ServicioFormSet = inlineformset_factory(Cobro,Servicio, form=ServicioForm,formset=RequiredBaseInlineFormSet, max_num=10, extra=1)
    servicio_formset = ServicioFormSet(request.POST or None, prefix='servicio')
    if cobro_form.is_valid() and servicio_formset.is_valid():
        cobro = cobro_form.save()
        servicio = servicio_formset.save(commit=False)
        for serv in servicio:
            serv.cobro = cobro
            serv.save()
        messages.add_message(request, messages.INFO, 'El cobro se ha registrado correctamente')
        return HttpResponseRedirect(cobro.get_absolute_url())
    return render_to_response(
        'cobranzas/nuevo_cobro.html', {
            'form': cobro_form,
            'formset': servicio_formset,
            'cliente': cliente,
        }, context_instance = RequestContext(request)
    )
views.py 文件源码 项目:Sermul 作者: CHOQUERC 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def EditarCobro(request,empleado_slug=None,cliente_slug=None,cobro_slug=None):
    if not request.user.is_staff or not request.user.is_superuser:
        raise Http404
    cliente = Cliente.objects.get(slug=cliente_slug)
    instance = Cobro.objects.get(slug=cobro_slug)
    cobro_form = CobroForm(request.POST or None,instance=instance)
    ServicioFormSet = inlineformset_factory(Cobro,Servicio, form=ServicioForm,formset=RequiredBaseInlineFormSet, max_num=10, extra=1)
    servicio_formset = ServicioFormSet(request.POST or None, prefix='servicio', instance=instance)
    if cobro_form.is_valid() and servicio_formset.is_valid():
        cobro = cobro_form.save()
        servicio = servicio_formset.save(commit=False)
        for serv in servicio:
            serv.cobro = cobro
            serv.save()
        messages.add_message(request, messages.INFO, 'El cobro se ha editado correctamente')
        return HttpResponseRedirect(cobro.get_absolute_url())
    return render_to_response(
        'cobranzas/nuevo_cobro.html', {
            'form': cobro_form,
            'formset': servicio_formset,
            'cliente': cliente,
        }, context_instance = RequestContext(request)
    )
views.py 文件源码 项目:Sermul 作者: CHOQUERC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def CreateLibros(request,empleado_slug=None,cliente_slug=None):
    uit_form = UITForm(request.POST or None)
    TipoLibroFormSet = inlineformset_factory(UIT, TipoLibro, form=TipoLibroForm,formset=RequiredBaseInlineFormSet, max_num=12, extra=1)
    tipolibro_formset = TipoLibroFormSet(request.POST or None, prefix='tipolibro')
    if uit_form.is_valid() and tipolibro_formset.is_valid():
        uit = uit_form.save()
        tipolibro = tipolibro_formset.save(commit=False)
        for lib in tipolibro:
            lib.uit = uit
            lib.save()
        messages.add_message(request, messages.INFO, 'Se ha registrado correctamente')
        return HttpResponseRedirect(uit.get_absolute_url())
    return render_to_response(
        'libros/libro_form.html', {
            'form': uit_form,
            'formset':tipolibro_formset,
        }, context_instance = RequestContext(request)
    )
views.py 文件源码 项目:Sermul 作者: CHOQUERC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def UpdateLibros(request,empleado_slug=None,cliente_slug=None,uit_pk=None):
    if not request.user.is_staff or not request.user.is_superuser:
        raise Http404
    instance = UIT.objects.get(pk=uit_pk)
    uit_form = UITForm(request.POST or None, instance=instance)
    TipoLibroFormSet = inlineformset_factory(UIT, TipoLibro, form=TipoLibroForm,formset=RequiredBaseInlineFormSet, max_num=12, extra=1)
    tipolibro_formset = TipoLibroFormSet(request.POST or None, prefix='tipolibro', instance=instance)
    if uit_form.is_valid() and tipolibro_formset.is_valid():
        uit = uit_form.save()
        tipolibro = tipolibro_formset.save(commit=False)
        for lib in tipolibro:
            lib.uit = uit
            lib.save()
        messages.add_message(request, messages.INFO, 'Se ha editado correctamente')
        return HttpResponseRedirect(uit.get_absolute_url())
    return render_to_response(
        'libros/libro_form.html', {
            'form': uit_form,
            'formset':tipolibro_formset,
        }, context_instance = RequestContext(request)
    )
forms.py 文件源码 项目:django-survey-formset 作者: hamdigdoura 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def nested_formset_factory(parent_model, child_model, grandchild_model):
    parent_child = inlineformset_factory(
        parent_model,
        child_model,
        formset=BaseNestedFormset,
        max_num=1,
        fields="__all__",
        widgets={'type': forms.RadioSelect(),
                 'text': forms.Textarea({'class': 'materialize-textarea'})
                 },
        extra=1,
        exclude=['help_text', 'order', ],
        can_order=True,
        can_delete=True,
    )

    parent_child.nested_formset_class = inlineformset_factory(
        child_model,
        grandchild_model,
        max_num=8,
        extra=4,
        validate_max=True,
        widgets={'text': forms.TextInput()},
        exclude=['ORDER', ],
        can_delete=True,
    )

    return parent_child

# The best link: http://yergler.net/blog/2009/09/27/nested-formsets-with-django/
# Nested formset
realtransactions.py 文件源码 项目:byro 作者: byro 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def formset_class(self):
        formset_class = inlineformset_factory(
            RealTransaction, VirtualTransaction, form=VirtualTransactionForm,
            formset=BaseModelFormSet, can_delete=True, extra=0,
        )
        return formset_class
inline.py 文件源码 项目:blog_django 作者: chnpmy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:dream_blog 作者: fanlion 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:djangoblog 作者: liuhuipy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
test_views.py 文件源码 项目:django-driver27 作者: SRJ9 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _test_season_formset(self, child_model, formset, fields):
        inline_formset = inlineformset_factory(Season, child_model, formset=formset,
                                               fields=fields,
                                               form=AlwaysChangedModelForm, can_delete=True)
        return inline_formset
cfp.py 文件源码 项目:pretalx 作者: pretalx 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def formset(self):
        formset_class = inlineformset_factory(
            Question, AnswerOption, form=AnswerOptionForm, formset=I18nFormSet,
            can_delete=True, extra=0,
        )
        return formset_class(
            self.request.POST if self.request.method == 'POST' else None,
            queryset=AnswerOption.objects.filter(question=self.get_object()) if self.get_object() else AnswerOption.objects.none(),
            event=self.request.event
        )
user.py 文件源码 项目:pretalx 作者: pretalx 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def formset(self):
        formset_class = inlineformset_factory(
            Submission, Resource, form=ResourceForm, formset=BaseModelFormSet,
            can_delete=True, extra=0,
        )
        obj = self.get_object()
        return formset_class(
            self.request.POST if self.request.method == 'POST' else None,
            files=self.request.FILES if self.request.method == 'POST' else None,
            queryset=obj.resources.all() if obj else Resource.objects.none(),
            prefix='resource',
        )
forms.py 文件源码 项目:beg-django-e-commerce 作者: Apress 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, model, widget=FormSetWidget, label=None, initial=None,
                 help_text=None, error_messages=None, show_hidden_initial=False, 
                 formset_factory=inlineformset_factory, *args, **kwargs):
        widget = widget(self)
        super(FormSetField, self).__init__(required=False, widget=widget, label=label, initial=initial, help_text=help_text, error_messages=error_messages, show_hidden_initial=show_hidden_initial)
        self.model = model
        self.formset_factory = formset_factory
        self.args = args
        self.kwargs = kwargs
inline.py 文件源码 项目:xadmin-markdown-editor 作者: bluenknight 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:YouPBX 作者: JoneXiong 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """?? BaseInlineFormSet ?"""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        #exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)
        return inlineformset_factory(self.parent_model, self.model, **defaults)
views.py 文件源码 项目:studentsdb 作者: PyDev777 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def user_profile(request):
    curr_user = request.user
    UserProfileInlineFormSet = inlineformset_factory(User, StProfile, form=ProfileForm, extra=2, can_delete=True)
    if request.method == "POST":
        form = UserForm(request.POST, request.FILES, instance=curr_user, prefix="main")
        formset = UserProfileInlineFormSet(request.POST, request.FILES, instance=curr_user, prefix="nested")
        if form.is_valid() and formset.is_valid():
            form.save()
            formset.save()
            return HttpResponseRedirect(reverse('home'))
    else:
        form = UserForm(instance=curr_user, prefix="main")
        formset = UserProfileInlineFormSet(instance=curr_user, prefix="nested")
    return TemplateResponse(request, "registration/profile.html", {"form": form, "formset": formset})
inline.py 文件源码 项目:eduDjango 作者: yuzhou6 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:Django-IMOOC-Shop 作者: LBruse 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:StudyOnline 作者: yipwinghong 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:xadmin_python3 作者: mahongquan 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:Django-shop 作者: poetries 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:MoocOnline 作者: My-captain 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:followme 作者: wzqnls 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:mxonline 作者: huwei86 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:mes 作者: osess 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)
        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:Charlotte 作者: LiZoRN 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)
inline.py 文件源码 项目:imooc-django 作者: zaxlct 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_formset(self, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)
        exclude.extend(self.get_readonly_fields())
        if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only if the
            # InlineModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)
        # if exclude is an empty list we use None, since that's the actual
        # default
        exclude = exclude or None
        can_delete = self.can_delete and self.has_delete_permission()
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            'fields': forms.ALL_FIELDS,
            "exclude": exclude,
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
            "can_delete": can_delete,
        }
        defaults.update(kwargs)

        return inlineformset_factory(self.parent_model, self.model, **defaults)


问题


面经


文章

微信
公众号

扫码关注公众号