#27976: label_from_instance fails silently: form field disappears.
-------------------------------------+-------------------------------------
     Reporter:  Wim Feijen           |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Forms                |                  Version:  1.8
     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 kapil garg):

 I tested it without crispy_form on dev version and it does throw an
 Exception. Here are the code samples i used


 {{{
 class Question(models.Model):
     question_text = models.CharField(max_length=200)
     pub_date = models.DateTimeField('date published')
     def __str__(self):
         return self.question_text


 class Choice(models.Model):
     question = models.ForeignKey(Question, on_delete=models.CASCADE)
     choice_text = models.CharField(max_length=200)
     votes = models.IntegerField(default=0)
     def __str__(self):
         return self.choice_text

 class TestForm(ModelForm):
     def __init__(self, *args, **kwargs):
         super(TestForm, self).__init__(*args, **kwargs)
         self.fields['question'].label_from_instance = lambda obj: obj.name
     class Meta:
         model = Choice
         fields = ['question', 'choice_text']
 }}}

 So i assume, crispy_forms has to do something with that behaviour.

--
Ticket URL: <https://code.djangoproject.com/ticket/27976#comment:3>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.740e7216e3fdb941f48d89fe64fdb93c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to