mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
newforms-admin: Removed the leading underscore from modelforms factory functions.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7605 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4530a408c4
commit
1fd3db4ab0
@ -1,7 +1,7 @@
|
||||
from django import oldforms, template
|
||||
from django import newforms as forms
|
||||
from django.newforms.formsets import all_valid
|
||||
from django.newforms.models import _modelform_factory, _inlineformset_factory
|
||||
from django.newforms.models import modelform_factory, inlineformset_factory
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.admin import widgets
|
||||
from django.contrib.admin.util import get_deleted_objects
|
||||
@ -318,7 +318,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
fields = flatten_fieldsets(self.declared_fieldsets)
|
||||
else:
|
||||
fields = None
|
||||
return _modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=self.formfield_for_dbfield)
|
||||
return modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=self.formfield_for_dbfield)
|
||||
|
||||
def get_formsets(self, request, obj=None):
|
||||
for inline in self.inline_instances:
|
||||
@ -717,7 +717,7 @@ class InlineModelAdmin(BaseModelAdmin):
|
||||
fields = flatten_fieldsets(self.declared_fieldsets)
|
||||
else:
|
||||
fields = None
|
||||
return _inlineformset_factory(self.parent_model, self.model, form=self.form, fk_name=self.fk_name, fields=fields, formfield_callback=self.formfield_for_dbfield, extra=self.extra)
|
||||
return inlineformset_factory(self.parent_model, self.model, form=self.form, fk_name=self.fk_name, fields=fields, formfield_callback=self.formfield_for_dbfield, extra=self.extra)
|
||||
|
||||
def get_fieldsets(self, request, obj=None):
|
||||
if self.declared_fieldsets:
|
||||
|
@ -279,8 +279,7 @@ class BaseModelForm(BaseForm):
|
||||
class ModelForm(BaseModelForm):
|
||||
__metaclass__ = ModelFormMetaclass
|
||||
|
||||
# XXX: This API *will* change. Use at your own risk.
|
||||
def _modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
||||
def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
||||
formfield_callback=lambda f: f.formfield()):
|
||||
# HACK: we should be able to construct a ModelForm without creating
|
||||
# and passing in a temporary inner class
|
||||
@ -369,15 +368,14 @@ class BaseModelFormSet(BaseFormSet):
|
||||
form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
|
||||
super(BaseModelFormSet, self).add_fields(form, index)
|
||||
|
||||
# XXX: Use at your own risk. This API *will* change.
|
||||
def _modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
|
||||
def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
|
||||
formset=BaseModelFormSet,
|
||||
extra=1, can_delete=False, can_order=False,
|
||||
fields=None, exclude=None):
|
||||
"""
|
||||
Returns a FormSet class for the given Django model class.
|
||||
"""
|
||||
form = _modelform_factory(model, form=form, fields=fields, exclude=exclude,
|
||||
form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
|
||||
formfield_callback=formfield_callback)
|
||||
FormSet = _formset_factory(form, formset, extra=extra, can_order=can_order, can_delete=can_delete)
|
||||
FormSet.model = model
|
||||
@ -444,8 +442,7 @@ def _get_foreign_key(parent_model, model, fk_name=None):
|
||||
return fk
|
||||
|
||||
|
||||
# XXX: This API *will* change. Use at your own risk.
|
||||
def _inlineformset_factory(parent_model, model, form=ModelForm,
|
||||
def inlineformset_factory(parent_model, model, form=ModelForm,
|
||||
formset=BaseInlineFormset, fk_name=None,
|
||||
fields=None, exclude=None,
|
||||
extra=3, can_order=False, can_delete=True,
|
||||
@ -463,7 +460,7 @@ def _inlineformset_factory(parent_model, model, form=ModelForm,
|
||||
exclude.append(fk.name)
|
||||
else:
|
||||
exclude = [fk.name]
|
||||
FormSet = _modelformset_factory(model, form=form,
|
||||
FormSet = modelformset_factory(model, form=form,
|
||||
formfield_callback=formfield_callback,
|
||||
formset=formset,
|
||||
extra=extra, can_delete=can_delete, can_order=can_order,
|
||||
|
@ -16,10 +16,10 @@ class Book(models.Model):
|
||||
|
||||
__test__ = {'API_TESTS': """
|
||||
|
||||
>>> from django.newforms.models import _modelformset_factory
|
||||
>>> from django.newforms.models import modelformset_factory
|
||||
|
||||
>>> qs = Author.objects.all()
|
||||
>>> AuthorFormSet = _modelformset_factory(Author, extra=3)
|
||||
>>> AuthorFormSet = modelformset_factory(Author, extra=3)
|
||||
|
||||
>>> formset = AuthorFormSet(queryset=qs)
|
||||
>>> for form in formset.forms:
|
||||
@ -55,7 +55,7 @@ restrict the Author objects we edit, but in this case we'll use it to display
|
||||
them in alphabetical order by name.
|
||||
|
||||
>>> qs = Author.objects.order_by('name')
|
||||
>>> AuthorFormSet = _modelformset_factory(Author, extra=1, can_delete=False)
|
||||
>>> AuthorFormSet = modelformset_factory(Author, extra=1, can_delete=False)
|
||||
|
||||
>>> formset = AuthorFormSet(queryset=qs)
|
||||
>>> for form in formset.forms:
|
||||
@ -94,7 +94,7 @@ This probably shouldn't happen, but it will. If an add form was marked for
|
||||
deltetion, make sure we don't save that form.
|
||||
|
||||
>>> qs = Author.objects.order_by('name')
|
||||
>>> AuthorFormSet = _modelformset_factory(Author, extra=1, can_delete=True)
|
||||
>>> AuthorFormSet = modelformset_factory(Author, extra=1, can_delete=True)
|
||||
|
||||
>>> formset = AuthorFormSet(queryset=qs)
|
||||
>>> for form in formset.forms:
|
||||
@ -163,9 +163,9 @@ True
|
||||
We can also create a formset that is tied to a parent model. This is how the
|
||||
admin system's edit inline functionality works.
|
||||
|
||||
>>> from django.newforms.models import _inlineformset_factory
|
||||
>>> from django.newforms.models import inlineformset_factory
|
||||
|
||||
>>> AuthorBooksFormSet = _inlineformset_factory(Author, Book, can_delete=False, extra=3)
|
||||
>>> AuthorBooksFormSet = inlineformset_factory(Author, Book, can_delete=False, extra=3)
|
||||
>>> author = Author.objects.get(name='Charles Baudelaire')
|
||||
|
||||
>>> formset = AuthorBooksFormSet(instance=author)
|
||||
@ -199,7 +199,7 @@ Now that we've added a book to Charles Baudelaire, let's try adding another
|
||||
one. This time though, an edit form will be available for every existing
|
||||
book.
|
||||
|
||||
>>> AuthorBooksFormSet = _inlineformset_factory(Author, Book, can_delete=False, extra=2)
|
||||
>>> AuthorBooksFormSet = inlineformset_factory(Author, Book, can_delete=False, extra=2)
|
||||
>>> author = Author.objects.get(name='Charles Baudelaire')
|
||||
|
||||
>>> formset = AuthorBooksFormSet(instance=author)
|
||||
|
@ -15,13 +15,13 @@ class Child(models.Model):
|
||||
|
||||
__test__ = {'API_TESTS': """
|
||||
|
||||
>>> from django.newforms.models import _inlineformset_factory
|
||||
>>> from django.newforms.models import inlineformset_factory
|
||||
|
||||
|
||||
Child has two ForeignKeys to Parent, so if we don't specify which one to use
|
||||
for the inline formset, we should get an exception.
|
||||
|
||||
>>> ifs = _inlineformset_factory(Parent, Child)
|
||||
>>> ifs = inlineformset_factory(Parent, Child)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
Exception: <class 'regressiontests.inline_formsets.models.Child'> has more than 1 ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>
|
||||
@ -29,14 +29,14 @@ Exception: <class 'regressiontests.inline_formsets.models.Child'> has more than
|
||||
|
||||
These two should both work without a problem.
|
||||
|
||||
>>> ifs = _inlineformset_factory(Parent, Child, fk_name='mother')
|
||||
>>> ifs = _inlineformset_factory(Parent, Child, fk_name='father')
|
||||
>>> ifs = inlineformset_factory(Parent, Child, fk_name='mother')
|
||||
>>> ifs = inlineformset_factory(Parent, Child, fk_name='father')
|
||||
|
||||
|
||||
If we specify fk_name, but it isn't a ForeignKey from the child model to the
|
||||
parent model, we should get an exception.
|
||||
|
||||
>>> ifs = _inlineformset_factory(Parent, Child, fk_name='school')
|
||||
>>> ifs = inlineformset_factory(Parent, Child, fk_name='school')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
Exception: fk_name 'school' is not a ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>
|
||||
@ -45,7 +45,7 @@ Exception: fk_name 'school' is not a ForeignKey to <class 'regressiontests.inlin
|
||||
If the field specified in fk_name is not a ForeignKey, we should get an
|
||||
exception.
|
||||
|
||||
>>> ifs = _inlineformset_factory(Parent, Child, fk_name='test')
|
||||
>>> ifs = inlineformset_factory(Parent, Child, fk_name='test')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'
|
||||
|
Loading…
x
Reference in New Issue
Block a user