Ticket #15125: introspec_meta.2.diff

File introspec_meta.2.diff, 2.8 KB (added by sontek, 5 years ago)
  • django/views/generic/edit.py

     
    8686        kwargs.update({'instance': self.object})
    8787        return kwargs
    8888
     89    def get_queryset(self):
     90        """
     91        Get the queryset to look an object up against. May not be called if
     92        `get_object` is overridden.
     93        """
     94        if self.queryset is None:
     95            if self.form_class:
     96                return self.form_class._meta.model._default_manager.all()
     97            else:
     98                return super(ModelFormMixin, self).get_queryset()
     99
    89100    def get_success_url(self):
    90101        if self.success_url:
    91102            url = self.success_url % self.object.__dict__
  • tests/regressiontests/generic_views/edit.py

     
    201201        except ImproperlyConfigured:
    202202            pass
    203203
     204    def test_update_with_form_class(self):
     205        a = Author.objects.create(
     206            name='Randall Munroe',
     207            slug='randall-munroe',
     208        )
     209        res = self.client.post('/edit/author/%d/update/formclass/' % a.pk,
     210                        {'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
     211        self.assertEqual(res.status_code, 302)
     212        self.assertRedirects(res, 'http://testserver/edit/authors/create/')
     213        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
     214
    204215class DeleteViewTests(TestCase):
    205216    urls = 'regressiontests.generic_views.urls'
    206217
  • tests/regressiontests/generic_views/urls.py

     
    11from django.conf.urls.defaults import *
    2 from django.views.generic import TemplateView
     2from django.views.generic import TemplateView, UpdateView
     3from regressiontests.generic_views.forms import AuthorForm
    34
    45import views
    56
     
    6465        views.NaiveAuthorUpdate.as_view()),
    6566    (r'^edit/author/(?P<pk>\d+)/update/redirect/$',
    6667        views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')),
     68    (r'^edit/author/(?P<pk>\d+)/update/formclass/$',
     69        UpdateView.as_view(form_class=AuthorForm,
     70            success_url='/edit/authors/create/')),
    6771    (r'^edit/author/(?P<pk>\d+)/update/interpolate_redirect/$',
    6872        views.NaiveAuthorUpdate.as_view(success_url='/edit/author/%(id)d/update/')),
    6973    (r'^edit/author/(?P<pk>\d+)/update/$',
Back to Top