Re: Model uniqueness constraint with date extraction

2020-02-18 Thread Simon Charette
Hello Thierry, Django doesn't support support constraints on lookups/expressions but there's ungoing work to do so[0]. In the mean time you'll have to rely on a `RunSQL` operation in your migrations to create the constraint. Cheers, Simon [0] https://code.djangoproject.com/ticket/30916 Le m

Model uniqueness constraint with date extraction

2020-02-18 Thread Thierry Backes
Hey, I have a model which has a date and a foreign key field. I want a uniqueness constraint that each fk can only be used once per month, so Unique(date__year, date__month, fk). However, when I use this in my model’s metadata: models.UniqueConstraint(fields=['date__year', 'date__month',