| | 2 | |
| | 3 | Something like this django.db.models.fields.related.ForeignKey: |
| | 4 | |
| | 5 | |
| | 6 | {{{ |
| | 7 | class ForeignKey(ForeignObject): |
| | 8 | |
| | 9 | def check(self, **kwargs): |
| | 10 | return [ |
| | 11 | *super().check(**kwargs), |
| | 12 | *self._check_on_delete(), |
| | 13 | *self._check_unique(), |
| | 14 | *self._check_pk_int(), |
| | 15 | ] |
| | 16 | |
| | 17 | def _check_pk_int(self): |
| | 18 | remote_pk = getattr(self.remote_field, 'pk', None) |
| | 19 | if isinstance(remote_pk, int): |
| | 20 | return [] |
| | 21 | else: |
| | 22 | return [ |
| | 23 | checks.Warning( |
| | 24 | 'Not integer primary key may lead you to unpredictable url in admin when ForeignKeyRawIdWidget is used', |
| | 25 | hint='Use extra quote() in this relation', |
| | 26 | obj=self, |
| | 27 | id='fields.W346', |
| | 28 | ) |
| | 29 | ] |
| | 30 | }}} |