cachalot/admin_tests/models.py
raw| 1 | from django.conf import settings |
| 2 | from django.db.models import Q, UniqueConstraint, Model, CharField, ForeignKey, SET_NULL |
| 3 | |
| 4 | |
| 5 | class TestModel(Model): |
| 6 | name = CharField(max_length=20) |
| 7 | owner = ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, |
| 8 | on_delete=SET_NULL) |
| 9 | |
| 10 | class Meta: |
| 11 | ordering = ('name',) |
| 12 | constraints = [ |
| 13 | UniqueConstraint( |
| 14 | fields=["name"], |
| 15 | condition=Q(owner=None), |
| 16 | name="unique_name", |
| 17 | ) |
| 18 | ] |