(self, date_checks)
| 1581 | return errors |
| 1582 | |
| 1583 | def _perform_date_checks(self, date_checks): |
| 1584 | errors = {} |
| 1585 | for model_class, lookup_type, field, unique_for in date_checks: |
| 1586 | lookup_kwargs = {} |
| 1587 | # there's a ticket to add a date lookup, we can remove this special |
| 1588 | # case if that makes it's way in |
| 1589 | date = getattr(self, unique_for) |
| 1590 | if date is None: |
| 1591 | continue |
| 1592 | if lookup_type == "date": |
| 1593 | lookup_kwargs["%s__day" % unique_for] = date.day |
| 1594 | lookup_kwargs["%s__month" % unique_for] = date.month |
| 1595 | lookup_kwargs["%s__year" % unique_for] = date.year |
| 1596 | else: |
| 1597 | lookup_kwargs["%s__%s" % (unique_for, lookup_type)] = getattr( |
| 1598 | date, lookup_type |
| 1599 | ) |
| 1600 | lookup_kwargs[field] = getattr(self, field) |
| 1601 | |
| 1602 | qs = model_class._default_manager.filter(**lookup_kwargs) |
| 1603 | # Exclude the current object from the query if we are editing an |
| 1604 | # instance (as opposed to creating a new one) |
| 1605 | if not self._state.adding and self._is_pk_set(): |
| 1606 | qs = qs.exclude(pk=self.pk) |
| 1607 | |
| 1608 | if qs.exists(): |
| 1609 | errors.setdefault(field, []).append( |
| 1610 | self.date_error_message(lookup_type, field, unique_for) |
| 1611 | ) |
| 1612 | return errors |
| 1613 | |
| 1614 | def date_error_message(self, lookup_type, field_name, unique_for): |
| 1615 | opts = self._meta |
no test coverage detected