mirror of
https://github.com/django/django.git
synced 2025-11-24 21:00:12 +00:00
Fixed #22135 -- Added ModelAdmin.get_changeform_initial_data().
Allows custom behavior for setting initial form data in ModelAdmin. By default, initial data is set via GET params. The new method allows this behavior to be overridden. Thanks egasimus for the suggestion.
This commit is contained in:
parent
6b63742ce5
commit
6acaa52386
5 changed files with 53 additions and 10 deletions
|
|
@ -765,6 +765,19 @@ class AdminViewFormUrlTest(TestCase):
|
|||
self.assertTrue('form_url' in response.context, msg='form_url not present in response.context')
|
||||
self.assertEqual(response.context['form_url'], 'pony')
|
||||
|
||||
def testInitialDataCanBeOverridden(self):
|
||||
"""
|
||||
Tests that the behavior for setting initial
|
||||
form data can be overridden in the ModelAdmin class.
|
||||
|
||||
Usually, the initial value is set via the GET params.
|
||||
"""
|
||||
response = self.client.get('/test_admin/%s/admin_views/restaurant/add/' % self.urlbit, {'name': 'test_value'})
|
||||
# this would be the usual behaviour
|
||||
self.assertNotContains(response, 'value="test_value"')
|
||||
# this is the overridden behaviour
|
||||
self.assertContains(response, 'value="overridden_value"')
|
||||
|
||||
|
||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class AdminJavaScriptTest(TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue