Re: [Django] #25787: Existence checks for related database sets

2015-11-20 Thread Django
#25787: Existence checks for related database sets
-+-
 Reporter:  JustusAdam   |Owner:
 |  andersonresende
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  ManyToMany,  | Triage Stage:
  contains, in   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  1|UI/UX:  0
-+-
Changes (by andersonresende):

 * owner:  nobody => andersonresende
 * needs_better_patch:   => 0
 * status:  new => assigned
 * needs_tests:   => 0
 * needs_docs:   => 0


--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.bbe83577bd1180e7ef7ebcb12bf57ab2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #25787: Existence checks for related database sets

2015-11-20 Thread Django
#25787: Existence checks for related database sets
-+-
 Reporter:  JustusAdam   |  Owner:  nobody
 Type:  New feature  | Status:  new
Component:  Database layer   |Version:  1.8
  (models, ORM)  |   Keywords:  ManyToMany, contains,
 Severity:  Normal   |  in
 Triage Stage:  Unreviewed   |  Has patch:  0
Easy pickings:  1|  UI/UX:  0
-+-
 I have recently had to check for presence of a particular object in a set
 of related objects (either ManyToMany or ForeignKey) and I found it
 unnecessary cumbersome not to be able to use the
 {{{in}}} operator.

 I propose to add an implementation of the {{{__contains__}}} method to the
 {{{ManyRelatedManager}}} object which executes something like the
 following query:

 {{{
 def __contains__(self, obj):
 return self.filter(id=obj.id).exists()
 }}}

 which would enable the following sample behaviour:

 {{{
 my_student = request.user.student
 my_course = Course.objects.get(id=course_id)
 is_teacher = my_student in my_course.teachers
 }}}

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.786827c8fb9d86ce9171b6fb5e740408%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.