#34129: Admin list_editable failed to edit -------------------------------+-------------------------------------- Reporter: Djing | Owner: Djing Type: Bug | Status: assigned Component: contrib.admin | Version: 3.2 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+--------------------------------------
Comment (by Djing): Replying to [comment:2 Josh Michael Karamuth]: This is my first time writing PR for django, and I follow the doc step by step. Now I'm having some problems with the test. After modifying the code as mentioned before, there are 2 existing tests which located in **model_formsets.tests.ModelFormsetTest** failed. {{{ def test_prevent_change_outer_model_and_create_invalid_data(self): author = Author.objects.create(name="Charles") other_author = Author.objects.create(name="Walt") AuthorFormSet = modelformset_factory(Author, fields="__all__") data = { "form-TOTAL_FORMS": "2", "form-INITIAL_FORMS": "2", "form-MAX_NUM_FORMS": "", "form-0-id": str(author.id), "form-0-name": "Charles", "form-1-id": str(other_author.id), # A model not in the formset's queryset. "form-1-name": "Changed name", } # This formset is only for Walt Whitman and shouldn't accept data for # other_author. formset = AuthorFormSet( data=data, queryset=Author.objects.filter(id__in=(author.id,)) ) self.assertTrue(formset.is_valid()) formset.save() # The name of other_author shouldn't be changed and new models aren't # created. self.assertSequenceEqual(Author.objects.all(), [author, other_author]) def test_edit_only_object_outside_of_queryset(self): charles = Author.objects.create(name="Charles Baudelaire") walt = Author.objects.create(name="Walt Whitman") data = { "form-TOTAL_FORMS": "1", "form-INITIAL_FORMS": "1", "form-0-id": walt.pk, "form-0-name": "Parth Patil", } AuthorFormSet = modelformset_factory(Author, fields="__all__", edit_only=True) formset = AuthorFormSet(data, queryset=Author.objects.filter(pk=charles.pk)) self.assertIs(formset.is_valid(), True) formset.save() self.assertCountEqual(Author.objects.all(), [charles, walt]) }}} They both give the formset a non-default queryset and pass data not in the queryset, and see if it just work for data in the queryset.(It seems just the opposite of mine). So, only one of two situations can pass the test for {{{self.assertTrue(formset.is_valid())}}}, either theirs or mine. I don't know how to deal with this situation. Or just as [comment:5 David Sanders] says: >It may be better to have the valid manager as the non-default and get the admin to use this instead -- Ticket URL: <https://code.djangoproject.com/ticket/34129#comment:6> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/01070184367cbddb-6abda37d-a459-4367-bc4e-6957ff2c0b88-000000%40eu-central-1.amazonses.com.