Ticket #1021: scm-4828-unique-together-might-be-null.diff

File scm-4828-unique-together-might-be-null.diff, 761 bytes (added by David Danier <goliath.mailinglist@…>, 18 years ago)

Patch for unique_together containing fields that might be NULL, (, None) could perhaps be replaced with EMPTY_VALUES from newforms

  • home/ddanier/django-unique-together/django/db/models/manipulators.py

     
    294294            # doesn't have blank=True.
    295295            return
    296296        if isinstance(f.rel, ManyToOneRel):
    297             kwargs['%s__pk' % f.name] = field_val
     297            if field_val in ('', None) and f.null:
     298                kwargs['%s__isnull' % f.name] = True
     299            else:
     300                kwargs['%s__pk' % f.name] = field_val
    298301        else:
    299302            kwargs['%s__iexact' % f.name] = field_val
    300303    try:
Back to Top