Ticket #13717: 13717_fix_unique_for.diff

File 13717_fix_unique_for.diff, 1.3 KB (added by Satoru Logic, 14 years ago)

Make sure the value of the unique_for field is not None before making the query.

  • db/models/base.py

     
    798798            # there's a ticket to add a date lookup, we can remove this special
    799799            # case if that makes it's way in
    800800            date = getattr(self, unique_for)
    801             if lookup_type == 'date':
    802                 lookup_kwargs['%s__day' % unique_for] = date.day
    803                 lookup_kwargs['%s__month' % unique_for] = date.month
    804                 lookup_kwargs['%s__year' % unique_for] = date.year
     801            if date:
     802                if lookup_type == 'date':
     803                    lookup_kwargs['%s__day' % unique_for] = date.day
     804                    lookup_kwargs['%s__month' % unique_for] = date.month
     805                    lookup_kwargs['%s__year' % unique_for] = date.year
     806                else:
     807                    lookup_kwargs['%s__%s' % (unique_for, lookup_type)] = getattr(date, lookup_type)
    805808            else:
    806                 lookup_kwargs['%s__%s' % (unique_for, lookup_type)] = getattr(date, lookup_type)
     809                lookup_kwargs[unique_for] = None
    807810            lookup_kwargs[field] = getattr(self, field)
    808811
    809812            qs = model_class._default_manager.filter(**lookup_kwargs)
Back to Top