Re: Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-14 Thread Simon Charette
So this happened not to be supported in Django 3.0 either. But https://github.com/django/django/pull/12067 should add support for it. Le jeudi 14 novembre 2019 15:50:34 UTC-5, Simon Charette a écrit : > > For the record I haven' tested the above myself. > > It might only work on Django 3.0+ and

Re: Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-14 Thread Simon Charette
For the record I haven' tested the above myself. It might only work on Django 3.0+ and require you to pass `output_field=BooleanField()` to Func. Le jeudi 14 novembre 2019 09:46:48 UTC-5, Simon Charette a écrit : > > Hello there, > > I guess your example is not the best since this check could

Re: Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-14 Thread Simon Charette
Hello there, I guess your example is not the best since this check could be defined on Author.Meta.constraints directly but if you wanted to define such a check on Book anyway you'll have to define a function and refer to it in the check constraint using Func. Using RunSQL in your migrations

Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-13 Thread Olivier
Hello, Let say I want to enforce a database constraint saying a "book's author age is over 18". As you may guess, books and authors are each described with a Model subclass with a foreign key (in this example each book is written by a single author) linking both. class Author(models.Model):