Ticket #17650: baseform_contains.diff

File baseform_contains.diff, 1.3 KB (added by etox, 3 years ago)
  • django/forms/forms.py

     
    101101        for name in self.fields:
    102102            yield self[name]
    103103
     104    def __contains__(self, name):
     105        return name in self.fields
     106
    104107    def __getitem__(self, name):
    105108        "Returns a BoundField with the given name."
    106109        try:
  • tests/regressiontests/forms/tests/forms.py

     
    4242        self.assertHTMLEqual(str(p['first_name']), '<input type="text" name="first_name" value="John" id="id_first_name" />')
    4343        self.assertHTMLEqual(str(p['last_name']), '<input type="text" name="last_name" value="Lennon" id="id_last_name" />')
    4444        self.assertHTMLEqual(str(p['birthday']), '<input type="text" name="birthday" value="1940-10-9" id="id_birthday" />')
     45        self.assertTrue('first_name' in p)
     46        self.assertFalse('nonexistentfield' in p)
    4547        try:
    4648            p['nonexistentfield']
    4749            self.fail('Attempts to access non-existent fields should fail.')
Back to Top