Ticket #10349: manytomany_dynamic_initial_against_1.0.2.diff

File manytomany_dynamic_initial_against_1.0.2.diff, 777 bytes (added by fas, 16 years ago)

simple fix

  • django/db/models/fields/related.py

     
    916916        # If initial is passed in, it's a list of related objects, but the
    917917        # MultipleChoiceField takes a list of IDs.
    918918        if defaults.get('initial') is not None:
    919             defaults['initial'] = [i._get_pk_val() for i in defaults['initial']]
     919            initial = defaults['initial']
     920            if callable(initial):
     921                initial = initial()
     922            defaults['initial'] = [i._get_pk_val() for i in initial]
    920923        return super(ManyToManyField, self).formfield(**defaults)
    921924
    922925    def db_type(self):
Back to Top