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
Set instance (not queryset) for InlineFormSet in wizard. #1726
Closed
Closed
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
885798a
Set instance (not queryset) for InlineFormSet in wizard.
flibbertigibbet 8969142
Add test for bug #21259.
1075271
Tidying test case.
505a532
Make changes suggested by @timgraham.
57a23ca
Move models.py; formatting.
2f1699c
Formatting
d4a7dfb
Formatting
9e894f5
Formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# coding: utf-8 | ||
from django.db import models | ||
from django.utils.encoding import python_2_unicode_compatible | ||
|
||
@python_2_unicode_compatible | ||
class Poet(models.Model): | ||
class Meta: | ||
app_label = 'formtools' | ||
|
||
name = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
@python_2_unicode_compatible | ||
class Poem(models.Model): | ||
class Meta: | ||
app_label = 'formtools' | ||
|
||
poet = models.ForeignKey(Poet) | ||
name = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
WizardTestKwargs, | ||
WizardTestGenericViewInterface, | ||
WizardFormKwargsOverrideTests, | ||
WizardInlineFormSetTests, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,16 @@ | |
from django.contrib.auth.tests.utils import skipIfCustomUser | ||
from django.contrib.formtools.wizard.views import CookieWizardView | ||
from django.utils._os import upath | ||
from django.contrib.formtools.tests.models import Poet, Poem | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be 2 newlines above class names as before |
||
|
||
class UserForm(forms.ModelForm): | ||
class Meta: | ||
model = User | ||
fields = '__all__' | ||
|
||
|
||
UserFormSet = forms.models.modelformset_factory(User, form=UserForm, extra=2) | ||
PoemFormSet = forms.models.inlineformset_factory(Poet, Poem, fields="__all__") | ||
|
||
|
||
class WizardTests(object): | ||
|
@@ -405,3 +406,24 @@ def get_form_kwargs(self, step): | |
self.assertEqual(formset.initial_form_count(), 1) | ||
self.assertEqual(['staff@example.com'], | ||
list(formset.queryset.values_list('email', flat=True))) | ||
|
||
|
||
class WizardInlineFormSetTests(TestCase): | ||
def setUp(self): | ||
self.rf = RequestFactory() | ||
self.poet = Poet.objects.create(name='test') | ||
self.poem = self.poet.poem_set.create(name='test poem') | ||
|
||
def test_set_instance(self): | ||
poet = self.poet | ||
class InlineFormSetWizard(CookieWizardView): | ||
instance = None | ||
def get_form_instance(self, step): | ||
if self.instance is None: | ||
self.instance = poet | ||
return self.instance | ||
|
||
view = InlineFormSetWizard.as_view([PoemFormSet]) | ||
response = view(self.rf.get('/')) | ||
formset = response.context_data['wizard']['form'] | ||
self.assertEqual(formset.instance, self.poet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/#model-style for the ordering of fields and
Meta
class.also two spaces above class names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, done.