#26970: Disabled ModelMultipleChoiceField does not validate anymore
-------------------------------+--------------------------------------
     Reporter:  karyon         |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Uncategorized  |                  Version:  1.10
     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 karyon):

 here are two tests:


 {{{
 def test_disabled_model_multiple_choice_field(self):
     class WriterForm(forms.Form):
         persons =
 forms.ModelMultipleChoiceField(queryset=Writer.objects.all())

     person1 = Writer.objects.create(name="Person 1")
     form = WriterForm(data={'persons': [person1.pk]})
     self.assertTrue(form.is_valid())
     form = WriterForm(data={'persons': [person1.pk]})
     form.fields['persons'].disabled = True
     self.assertTrue(form.is_valid())

 def test_disabled_model_multiple_choice_field2(self):
     class ArticleCategoriesForm(forms.ModelForm):
         categories =
 forms.ModelMultipleChoiceField(Category.objects.all(), required=False)

         class Meta:
             model = Article
             fields = ['categories']

     category1 = Category.objects.create(name="uiae")
     article1 = Article.objects.create(
                 pub_date=datetime.date(1988, 1, 4),
                 writer=Writer.objects.create(name='Test writer'),
                 # categories= [category1.pk], # throws a warning
             )
     article1.categories.set([category1.pk]) # without this, the test
 passes
     # article1.categories = [category1.pk] # throws a warning

     # instance must be set, otherwise test passes
     form = ArticleCategoriesForm(data={'categories': [category1.pk]},
 instance=article1)
     self.assertTrue(form.is_valid())
     form = ArticleCategoriesForm(data={'categories': [category1.pk]},
 instance=article1)
     form.fields['categories'].disabled = True
     self.assertTrue(form.is_valid())
 }}}

 both fail at the second assert, the first one with "this field is
 required" (setting it to required=False or disabled=False makes the test
 pass), the second one with "please enter a list of values", like the
 original report.

 i'm not sure what the protocol is, should i put the code somewhere else?

 unrelated: note the warnings when assigning article.categories. the
 warning was "Direct assignment to the reverse side of a related set is
 deprecated due to the implicit save() that happens. Use article_set.set()
 instead." although i was not assigning to the reverse side. should i file
 a separate bug?

--
Ticket URL: <https://code.djangoproject.com/ticket/26970#comment:7>
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.8fca599616229026902d5623fc7d9daf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to