Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved ModelForm check work when instance is given #783

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/modeltests/model_forms/tests.py
Expand Up @@ -133,6 +133,9 @@ class ShortCategory(forms.ModelForm):
slug = forms.CharField(max_length=5)
url = forms.CharField(max_length=3)

class Meta:
model = Category

class ImprovedArticleForm(forms.ModelForm):
class Meta:
model = ImprovedArticle
Expand Down Expand Up @@ -277,6 +280,19 @@ class BadForm(ArticleForm, BaseCategoryForm):
['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status']
)


def test_invalid_meta_model(self):
class InvalidModelForm(forms.ModelForm):
class Meta:
pass # no model.
# can't create new form
with self.assertRaises(ValueError):
f = InvalidModelForm()
# even if you provide a model instance
with self.assertRaises(ValueError):
f = InvalidModelForm(instance=Category)


def test_subcategory_form(self):
class SubCategoryForm(BaseCategoryForm):
""" Subclassing without specifying a Meta on the class will use
Expand Down