[Django] #20611: Add reverse unique field

30 views
Skip to first unread message

Django

unread,
Jun 16, 2013, 1:05:17 PM6/16/13
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: New | Status: new
feature | Version: master
Component: Database | Keywords:
layer (models, ORM) | Has patch: 0
Severity: Normal | Needs tests: 0
Triage Stage: | Easy pickings: 0
Unreviewed |
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
The idea is to add a model relation type by which one can query unique
reverse relations. For example, if you have Article and ArticleTranslation
then addition of "lang" restriction in the join from article to its
translation makes the join unique.

There are multiple situations where such a system is useful: a computer
can have multiple codes of different types, but for each code type the
code value is unique. A room in hotel can have single active reservation
per day.

The proposed patch adds a ReverseUnique(to_model, field_of_to_model,
filters) model field. For examples see the branch
https://github.com/akaariai/django/compare/reverse_unique, the test models
and tests itself contain some example of why this would be useful.

A more generic but a bit harder to implement feature is allowing
annotation of reverse unique values. There the idea would be that you
could do:
{{{
qs.annotate(translation_fi=ModelAnnotation(ArticleTranslation,
through_field='article_translations', filter=Q(lang='fi')))
}}}
then you could use translation_fi like any relation. I think model level
definition of the same thing will be useful in many cases (consider the
active_translation case), so there is room for both model field
implementation and annotation based implementation.

I will likely push the needed ORM & related.py changes into 1.6 but leave
other parts out. Pushing the changes to the new internal related field API
seems OK to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/20611>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 23, 2013, 4:36:23 AM7/23/13
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by akaariai):

* stage: Unreviewed => Accepted


Comment:

Accepting my own ticket - I need it :) I will see if I can get the ORM
changes still to 1.6.

--
Ticket URL: <https://code.djangoproject.com/ticket/20611#comment:1>

Django

unread,
Jul 23, 2013, 7:52:47 AM7/23/13
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by akaariai):

The ORM changes are really minor, and to a new API, so I will push these
to both 1.6 and master. After that the ReverseUnique field can be
implemented outside Django (although internal APIs must be used).

--
Ticket URL: <https://code.djangoproject.com/ticket/20611#comment:2>

Django

unread,
Jul 23, 2013, 8:19:06 AM7/23/13
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Anssi Kääriäinen <akaariai@…>):

In [changeset:"6b4967e88368934dbbb1f289c790ab813fa59c72"]:
{{{
#!CommitTicketReference repository=""
revision="6b4967e88368934dbbb1f289c790ab813fa59c72"
Minor change to get_extra_descriptor_filter()

Refs #20611.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20611#comment:3>

Django

unread,
Jul 23, 2013, 8:21:04 AM7/23/13
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Anssi Kääriäinen <akaariai@…>):

In [changeset:"43f1d51b4ba3ab2c0223928904e1d24c0571da8d"]:
{{{
#!CommitTicketReference repository=""
revision="43f1d51b4ba3ab2c0223928904e1d24c0571da8d"
[1.6.x] Minor change to get_extra_descriptor_filter()

Refs #20611. Backpatch of 6b4967e88368934dbbb1f289c790ab813fa59c72.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20611#comment:4>

Django

unread,
Jul 25, 2013, 9:50:03 AM7/25/13
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by akaariai):

* stage: Accepted => Someday/Maybe


Comment:

For those interested, an implementation exists at
https://github.com/akaariai/django-reverse-unique/, lets see if this type
of field will be useful enough for Django inclusion.

--
Ticket URL: <https://code.djangoproject.com/ticket/20611#comment:5>

Django

unread,
Jan 2, 2021, 2:53:22 PM1/2/21
to django-...@googlegroups.com
#20611: Add reverse unique field
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:

| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hannes Ljungberg):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of [https://code.djangoproject.com/ticket/29789 #29789] and
[https://code.djangoproject.com/ticket/27332 #27332].

--
Ticket URL: <https://code.djangoproject.com/ticket/20611#comment:6>

Reply all
Reply to author
Forward
0 new messages