              qs = model_class._default_manager.filter(**lookup_kwargs)
  
              # Exclude the current object from the query if we are editing an
              # instance (as opposed to creating a new one)
              if not self._state.adding and self.pk is not None:
                  qs = qs.exclude(pk=self.pk)
  
              if qs.exists():
                  if len(unique_check) == 1:
                      key = unique_check[0]
                  else:
                      key = NON_FIELD_ERRORS
 
</s> remove     InternalCertificationAudit, BusStation, TrainStation)
 </s> add     InternalCertificationAudit, BusStation, TrainStation, User, Profile)
            # Note that we need to use the pk as defined by model_class, not
            # self.pk. These can be different fields because model inheritance
            # allows single model to have effectively multiple primary keys.
            # Refs #17615.
            model_class_pk = self._get_pk_val(model_class._meta)
            if not self._state.adding and model_class_pk is not None:
                qs = qs.exclude(pk=model_class_pk)
              qs = model_class._default_manager.filter(**lookup_kwargs)
  
              # Exclude the current object from the query if we are editing an
              # instance (as opposed to creating a new one)
            # Note that we need to use the pk as defined by model_class, not
            # self.pk. These can be different fields because model inheritance
            # allows single model to have effectively multiple primary keys.
            # Refs #17615.
            model_class_pk = self._get_pk_val(model_class._meta)
            if not self._state.adding and model_class_pk is not None:
                qs = qs.exclude(pk=model_class_pk)
            # Note that we need to use the pk as defined by model_class, not
            # self.pk. These can be different fields because model inheritance
            # allows single model to have effectively multiple primary keys.
            # Refs #17615.
            model_class_pk = self._get_pk_val(model_class._meta)
            if not self._state.adding and model_class_pk is not None:
                qs = qs.exclude(pk=model_class_pk)
            # Note that we need to use the pk as defined by model_class, not
            # self.pk. These can be different fields because model inheritance
            # allows single model to have effectively multiple primary keys.
            # Refs #17615.
            model_class_pk = self._get_pk_val(model_class._meta)
            if not self._state.adding and model_class_pk is not None:
                qs = qs.exclude(pk=model_class_pk)
              if qs.exists():
                  if len(unique_check) == 1:
                      key = unique_check[0]
                  else:
                      key = NON_FIELD_ERRORS
keep keep keep keep replace replace replace keep keep keep keep keep
 Fixed #17615 -- Corrected unique field validation when using multitable inheritance. The validation used wrong pk value if the parent and child model had different pk fields. Thanks ungenio for the report and patch.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17920 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
django/db/models/base.py