Ticket #2965: ticket-2965.patch

File ticket-2965.patch, 1.6 KB (added by Ramiro Morales, 18 years ago)
  • django/db/models/manipulators.py

    old new  
    286286        # This is really not going to work for fields that have different
    287287        # form fields, e.g. DateTime.
    288288        # This validation needs to occur after html2python to be effective.
    289         field_val = all_data.get(f.attname, None)
    290         if field_val is None:
     289        field_val = f.get_manipulator_new_data(all_data)
     290        if not f.null and field_val is None:
    291291            # This will be caught by another validator, assuming the field
    292292            # doesn't have blank=True.
    293293            return
    294294        if isinstance(f.rel, ManyToOneRel):
    295             kwargs['%s__pk' % f.name] = field_val
     295            kwargs[f.get_validator_unique_lookup_type()] = field_val
    296296        else:
    297297            kwargs['%s__iexact' % f.name] = field_val
    298298    try:
     
    303303        pass
    304304    else:
    305305        raise validators.ValidationError, _("%(object)s with this %(type)s already exists for the given %(field)s.") % \
    306             {'object': capfirst(opts.verbose_name), 'type': field_list[0].verbose_name, 'field': get_text_list([f.verbose_name for f in field_list[1:]], 'and')}
     306            {'object': capfirst(opts.verbose_name), 'type': field_list[0].verbose_name, 'field': get_text_list([f.verbose_name for f in field_list[1:]], _('and'))}
    307307
    308308def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_type, self, field_data, all_data):
    309309    from django.db.models.fields.related import ManyToOneRel
Back to Top