Opened 6 years ago
Closed 6 years ago
#30972 closed New feature (duplicate)
USERNAME_FIELD UniqueConstraint option
| Reported by: | Iman Kermani | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.0 |
| Severity: | Normal | Keywords: | AbstractUser UniqueConstraint |
| Cc: | Iman Kermani | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I'm having a case that the User model USERNAME_FIELD is cellphone and at registration, cellphone should be verified with SMS OTP. Meanwhile, the User object should be created with is_verified = False , so in Meta class, I need a UniqueConstraint like the following code:
UniqueConstraint(fields=["cellphone"], condition=Q(is_verified=True), name="unique_is_active_cellphone")
Generally, I need to have the ability to create multiple users with the same username and have a unique Active or Verified in the system.
Change History (2)
comment:1 by , 6 years ago
| Cc: | added |
|---|
comment:2 by , 6 years ago
| Component: | contrib.auth → Database layer (models, ORM) |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
| Version: | 2.2 → 3.0 |
Note:
See TracTickets
for help on using tickets.
On PostgreSQL you should be able to implement this with ExclusionConstraint (available from Django 3.0). As far as I'm concerned they are not available on other databases.
Duplicate of #29824.