[Changeset] r10926 - in django/trunk: django/db/models django/db/models/sql tests/modeltests/defer

2009-06-05 Thread noreply

Author: russellm
Date: 2009-06-06 01:14:05 -0500 (Sat, 06 Jun 2009)
New Revision: 10926

Modified:
   django/trunk/django/db/models/query.py
   django/trunk/django/db/models/sql/query.py
   django/trunk/tests/modeltests/defer/models.py
Log:
Fixed #10572 -- Corrected the operation of the defer() and only() clauses when 
used on inherited models.

Modified: django/trunk/django/db/models/query.py
===
--- django/trunk/django/db/models/query.py  2009-06-05 20:58:34 UTC (rev 
10925)
+++ django/trunk/django/db/models/query.py  2009-06-06 06:14:05 UTC (rev 
10926)
@@ -190,7 +190,25 @@
 index_start = len(extra_select)
 aggregate_start = index_start + len(self.model._meta.fields)
 
-load_fields = only_load.get(self.model)
+load_fields = []
+# If only/defer clauses have been specified,
+# build the list of fields that are to be loaded.
+if only_load:
+for field, model in self.model._meta.get_fields_with_model():
+if model is None:
+model = self.model
+if field == self.model._meta.pk:
+# Record the index of the primary key when it is found
+pk_idx = len(load_fields)
+try:
+if field.name in only_load[model]:
+# Add a field that has been explicitly included
+load_fields.append(field.name)
+except KeyError:
+# Model wasn't explicitly listed in the only_load table
+# Therefore, we need to load all fields from this model
+load_fields.append(field.name)
+
 skip = None
 if load_fields and not fill_cache:
 # Some fields have been deferred, so we have to initialise

Modified: django/trunk/django/db/models/sql/query.py
===
--- django/trunk/django/db/models/sql/query.py  2009-06-05 20:58:34 UTC (rev 
10925)
+++ django/trunk/django/db/models/sql/query.py  2009-06-06 06:14:05 UTC (rev 
10926)
@@ -635,10 +635,10 @@
 # models.
 workset = {}
 for model, values in seen.iteritems():
-for field, f_model in model._meta.get_fields_with_model():
+for field in model._meta.local_fields:
 if field in values:
 continue
-add_to_dict(workset, f_model or model, field)
+add_to_dict(workset, model, field)
 for model, values in must_include.iteritems():
 # If we haven't included a model in workset, we don't add the
 # corresponding must_include fields for that model, since an
@@ -657,6 +657,12 @@
 # included any fields, we have to make sure it's mentioned
 # so that only the "must include" fields are pulled in.
 seen[model] = values
+# Now ensure that every model in the inheritance chain is mentioned
+# in the parent list. Again, it must be mentioned to ensure that
+# only "must include" fields are pulled in.
+for model in orig_opts.get_parent_list():
+if model not in seen:
+seen[model] = set()
 for model, values in seen.iteritems():
 callback(target, model, values)
 

Modified: django/trunk/tests/modeltests/defer/models.py
===
--- django/trunk/tests/modeltests/defer/models.py   2009-06-05 20:58:34 UTC 
(rev 10925)
+++ django/trunk/tests/modeltests/defer/models.py   2009-06-06 06:14:05 UTC 
(rev 10926)
@@ -17,6 +17,12 @@
 def __unicode__(self):
 return self.name
 
+class Child(Primary):
+pass
+
+class BigChild(Primary):
+other = models.CharField(max_length=50)
+
 def count_delayed_fields(obj, debug=False):
 """
 Returns the number of delayed attributes on the given model instance.
@@ -33,7 +39,7 @@
 
 __test__ = {"API_TEST": """
 To all outward appearances, instances with deferred fields look the same as
-normal instances when we examine attribut values. Therefore we test for the
+normal instances when we examine attribute values. Therefore we test for the
 number of deferred fields on returned instances (by poking at the internals),
 as a way to observe what is going on.
 
@@ -98,5 +104,89 @@
 >>> Primary.objects.all()
 []
 
+# Regression for #10572 - A subclass with no extra fields can defer fields 
from the base class
+>>> _ = Child.objects.create(name="c1", value="foo", related=s1)
 
+# You can defer a field on a baseclass when the subclass has no fields
+>>> obj = Child.objects.defer("value").get(name="c1")
+>>> count_delayed_fields(obj)
+1
+>>> obj.name
+u"c1"
+>>> obj.value
+u"foo"
+>>> obj.name = "c2"
+>>> 

Re: [Django] #4992: Alter cache key based on GET parameters

2009-06-05 Thread Django
#4992: Alter cache key based on GET parameters
-+--
  Reporter:  anonymous   | Owner:  nobody
Status:  reopened| Milestone:
 Component:  Cache system|   Version:  SVN   
Resolution:  |  Keywords:
 Stage:  Design decision needed  | Has_patch:  1 
Needs_docs:  0   |   Needs_tests:  0 
Needs_better_patch:  0   |  
-+--
Comment (by kmike):

 I've implemented something like Daniel Pope 's suggestion and opened
 separate ticket for that: #11269.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #11269: Allow key_prefix to be callable

2009-06-05 Thread Django
#11269: Allow key_prefix to be callable
--+-
 Reporter:  kmike |   Owner:  nobody
   Status:  new   |   Milestone:
Component:  Cache system  | Version:  SVN   
 Keywords:|   Stage:  Unreviewed
Has_patch:  1 |  
--+-
 "cache_page" decorator accepts "key_prefix" argument.

 If "cache_page" will allow "key_prefix" to be callable it will be easier
 to fine-tune view caching.
 For example, it will be easier to have per-user cache or to cache views
 based on specified GET parameters (there is dedicated #4992 ticket for
 that).

 I've attached patch for that feature.

 The sample syntax:

 {{{

 #have 2 static versions of the my_view response for authenticated and
 anonymous users

 def my_key_prefix(request):
 if request.GET:
 return None #magic value to disable caching

 if request.user.is_authenticated():
 return 'logged_in'
 else:
 return 'not_logged_in'

 @cache_control(must_revalidate=True)
 @cache_page(600, my_key_prefix)
 def my_view(request):
 ... #something is different for authenticated and anonymous users
 }}}


 {{{
 #cache my_paginated_view based on "page" parameter in query string

 def page_key_prefix(request):
 return request.GET.get('page','')

 @cache_page(60, page_key_prefix)
 def my_paginated_view(request)
  #page number is passed via 'page' GET parameter and used for
 pagination
 }}}

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10572: defer() doesn't work cleanly with model inheritance

2009-06-05 Thread Django
#10572: defer() doesn't work cleanly with model inheritance
---+
  Reporter:  mtredinnick   | Owner:  russellm
Status:  new   | Milestone:  1.1 
 Component:  Database layer (models, ORM)  |   Version:  SVN 
Resolution:|  Keywords:  
 Stage:  Accepted  | Has_patch:  0   
Needs_docs:  0 |   Needs_tests:  0   
Needs_better_patch:  0 |  
---+
Changes (by russellm):

  * owner:  mtredinnick => russellm

Comment:

 I've got a test and patch for this; however, the test has introduced an
 order dependency in the test suite. I'll commit once I've got this sorted
 out.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10395: GeoIP broken with [9945]

2009-06-05 Thread Django
#10395: GeoIP broken with [9945]
-+--
  Reporter:  anonymous   | Owner:  nobody
Status:  closed  | Milestone:  1.1   
 Component:  GIS |   Version:  SVN   
Resolution:  fixed   |  Keywords:
 Stage:  Unreviewed  | Has_patch:  0 
Needs_docs:  0   |   Needs_tests:  0 
Needs_better_patch:  0   |  
-+--
Changes (by Alex):

  * status:  reopened => closed
  * resolution:  => fixed

Comment:

 The line: if not settings._target doesn't exist in that revision, you're
 code somehow wasn't upgraded properly.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10395: GeoIP broken with [9945]

2009-06-05 Thread Django
#10395: GeoIP broken with [9945]
-+--
  Reporter:  anonymous   | Owner:  nobody
Status:  reopened| Milestone:  1.1   
 Component:  GIS |   Version:  SVN   
Resolution:  |  Keywords:
 Stage:  Unreviewed  | Has_patch:  0 
Needs_docs:  0   |   Needs_tests:  0 
Needs_better_patch:  0   |  
-+--
Changes (by mch):

  * status:  closed => reopened
  * resolution:  fixed =>

Comment:

 I'm seeing this issue with r10925 and Python 2.6.

 {{{
 >>> from django.contrib.gis.utils.geoip import geoip
 Traceback (most recent call last):
   File "", line 1, in 
   File "/usr/lib/python2.6/dist-
 packages/django/contrib/gis/utils/geoip.py", line 45, in 
 if not settings._target: settings.configure()
   File "/usr/lib/python2.6/dist-packages/django/utils/functional.py", line
 273, in __getattr__
 return getattr(self._wrapped, name)
 AttributeError: 'Settings' object has no attribute '_target'
 }}}

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11268: django.contrib.admin.util.quote does not handle spaces (%20 -> _20)

2009-06-05 Thread Django
#11268: django.contrib.admin.util.quote does not handle spaces (%20 -> _20)
---+
  Reporter:  mcsmart   | Owner:  nobody
Status:  new   | Milestone:
 Component:  django.contrib.admin  |   Version:  1.0   
Resolution:|  Keywords:
 Stage:  Unreviewed| Has_patch:  1 
Needs_docs:  0 |   Needs_tests:  1 
Needs_better_patch:  0 |  
---+
Changes (by Alex):

  * needs_better_patch:  => 0
  * needs_tests:  => 1
  * 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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #11268: django.contrib.admin.util.quote does not handle spaces (%20 -> _20)

2009-06-05 Thread Django
#11268: django.contrib.admin.util.quote does not handle spaces (%20 -> _20)
--+-
 Reporter:  mcsmart   |   Owner:  nobody
   Status:  new   |   Milestone:
Component:  django.contrib.admin  | Version:  1.0   
 Keywords:|   Stage:  Unreviewed
Has_patch:  1 |  
--+-
 I have a primary key that allows spaces, e.g., "foo bar", which comes
 up in the admin list page properly, but the
 URL becomes "http://example.com/admin/myapp/mymodel/foo%20bar/"; when I
 expect it to become "http://example.com/admin/myapp/mymodel/
 foo_20bar/".  If you follow the link you'll get a debug page with:

 """
 Page not found (404)
 Request Method: GET
 Request URL:http://example.com/admin/myapp/mymodel/foo%20bar/

 mymodel object with primary key u'foo%20bar' does not exist.
 """

 It seems that django.contrib.admin.util.quote should convert spaces
 along with the other characters it already does.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #2495: db.models.TextField cannot be marked unique when using mysql backend

2009-06-05 Thread Django
#2495: db.models.TextField cannot be marked unique when using mysql backend
---+
  Reporter:  anonymous | Owner:  Honza_Kral 

Status:  new   | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  SVN

Resolution:|  Keywords:  mysql 
TextField
 Stage:  Accepted  | Has_patch:  1  

Needs_docs:  0 |   Needs_tests:  0  

Needs_better_patch:  0 |  
---+
Changes (by Honza_Kral):

  * owner:  nobody => Honza_Kral
  * needs_better_patch:  1 => 0
  * needs_tests:  1 => 0

Comment:

 Added a new patch that have tests (failing without the patch) and more
 updated magic number. After discussing with jacob on #django-dev I only
 fixed the {{{db_index}}} property and not {{{unique}}} or
 {{{unique_together}}} since that doesn't make much sense for
 {{{TextField}}}s

 Please let me know it the approach taken in the patch is not welcome and I
 will update it.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11262: page consumes 100% cpu in firefox

2009-06-05 Thread Django
#11262: page consumes 100% cpu in firefox
+---
  Reporter:  josebrwn   | Owner:  nobody
Status:  closed | Milestone:  1.0.3 
 Component:  Documentation  |   Version:  1.0   
Resolution:  invalid|  Keywords:
 Stage:  Unreviewed | Has_patch:  0 
Needs_docs:  0  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Changes (by ubernostrum):

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

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #2495: db.models.TextField cannot be marked unique when using mysql backend

2009-06-05 Thread Django
#2495: db.models.TextField cannot be marked unique when using mysql backend
---+
  Reporter:  anonymous | Owner:  nobody 

Status:  new   | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  SVN

Resolution:|  Keywords:  mysql 
TextField
 Stage:  Accepted  | Has_patch:  1  

Needs_docs:  0 |   Needs_tests:  1  

Needs_better_patch:  1 |  
---+
Changes (by Almad):

 * cc: Almad (added)

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10190: Charset should be customizable with HttpResponse

2009-06-05 Thread Django
#10190: Charset should be customizable with HttpResponse
+---
  Reporter:  Wonlay | Owner:  ccahoon   

Status:  new| Milestone:  1.2   

 Component:  HTTP handling  |   Version:  SVN   

Resolution: |  Keywords:  HttpResponse, charset, 
runtime
 Stage:  Accepted   | Has_patch:  1 

Needs_docs:  0  |   Needs_tests:  0 

Needs_better_patch:  1  |  
+---
Comment (by ccahoon):

 http://www.iana.org/assignments/character-sets appears to be the canonical
 list of valid character sets.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10323: Dont force admin media serving with runserver management command.

2009-06-05 Thread Django
#10323: Dont force admin media serving with runserver management command.
+---
  Reporter:  MockSoul   | Owner:  nobody
Status:  new| Milestone:
 Component:  django-admin.py runserver  |   Version:  1.0   
Resolution: |  Keywords:
 Stage:  Accepted   | Has_patch:  1 
Needs_docs:  0  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Changes (by Rob Hudson ):

 * cc: treborhud...@gmail.com (added)

Comment:

 I'd actually like to see a discussion of how reusable Django apps can
 specify their own media and treat contrib.admin as just another reusable
 app.  I know a number of reusable apps that would like some hook into
 serving media via runserver without resorting to hacks or "copy files to
 your media folder" instructions.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10190: Charset should be customizable with HttpResponse

2009-06-05 Thread Django
#10190: Charset should be customizable with HttpResponse
+---
  Reporter:  Wonlay | Owner:  ccahoon   

Status:  new| Milestone:  1.2   

 Component:  HTTP handling  |   Version:  SVN   

Resolution: |  Keywords:  HttpResponse, charset, 
runtime
 Stage:  Accepted   | Has_patch:  1 

Needs_docs:  0  |   Needs_tests:  0 

Needs_better_patch:  1  |  
+---
Changes (by ccahoon):

  * owner:  nobody => ccahoon

Comment:

 >  2. Find out whether Python codec names are all valid as HTTP charset
 names. If so, parse the `content_type` to see if a special charset
 encoding is needed (no need for an extra `__init__` parameter).

 This is not the case. http://docs.python.org/library/codecs.html#standard-
 encodings ("A number of codecs are specific to Python, so their codec
 names have no meaning outside Python.") and
 http://www.cs.tut.fi/~jkorpela/chars/sorted.html which lacks a bunch of
 codecs listed in the first link.

 >  3. If the previous item is not applicable, don't use `_charset` in the
 `content_type` setting, since it could lead to invalid value (and we'll
 need a documentation update to clarify the requirements there).

 Such as a list of valid codecs?

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11267: ForeignKey/OneToOneField attribute names should be valid kwargs in queries

2009-06-05 Thread Django
#11267: ForeignKey/OneToOneField attribute names should be valid kwargs in 
queries
---+
  Reporter:  dstora| Owner:  nobody 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  1.0
  
Resolution:|  Keywords:  foreign 
key ForeignKey OneToOneField query filter
 Stage:  Design decision needed| Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Comment (by dstora):

 Indeed, I've changed the field name from "ccy_id" to "ccy" when making it
 a !ForeignKey field.[[BR]]
 I did it so that the id value can still be referenced to as "ccy_id":
 {{{
 p = Payment()
 #...
 if p.ccy_id == "USD":
 #...
 }}}
 So basically, the requirements so that one can add foreign key constraint
 without breaking existing code are:[[BR]]
 - To name the !ForeignKey/OneToOneField field differently and be able to
 decide the name Django uses for the id attribute (see ticket 11265)[[BR]]
 - To be able to use the id attribute name in queries[[BR]]

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11267: ForeignKey/OneToOneField attribute names should be valid kwargs in queries

2009-06-05 Thread Django
#11267: ForeignKey/OneToOneField attribute names should be valid kwargs in 
queries
---+
  Reporter:  dstora| Owner:  nobody 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  1.0
  
Resolution:|  Keywords:  foreign 
key ForeignKey OneToOneField query filter
 Stage:  Design decision needed| Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by Alex):

  * needs_better_patch:  => 0
  * stage:  Unreviewed => Design decision needed
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 I'd like to wontfix this, as I don't see any reduction in functionality,
 you've changed the field name.  However, I'm going to leave it open for a
 committer's opinion.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11266: ForeignKey/OneToOneField attribute names should be valid kwargs in queries

2009-06-05 Thread Django
#11266: ForeignKey/OneToOneField attribute names should be valid kwargs in 
queries
---+
  Reporter:  dstora| Owner:  nobody 
  
Status:  closed| Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  1.0
  
Resolution:  duplicate |  Keywords:  foreign 
key ForeignKey OneToOneField query filter
 Stage:  Unreviewed| Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by Alex):

  * status:  new => closed
  * needs_better_patch:  => 0
  * resolution:  => duplicate
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 Dupe of #11267.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #11267: ForeignKey/OneToOneField attribute names should be valid kwargs in queries

2009-06-05 Thread Django
#11267: ForeignKey/OneToOneField attribute names should be valid kwargs in 
queries
---+
 Reporter:  dstora |   Owner:  
nobody
   Status:  new|   Milestone:   
 
Component:  Database layer (models, ORM)   | Version:  
1.0   
 Keywords:  foreign key ForeignKey OneToOneField query filter  |   Stage:  
Unreviewed
Has_patch:  1  |  
---+
 Currently, only the field names are available as kwargs for queries.[[BR]]
 However, it makes (even more) sense that attribute names are supported too
 for !ForeignKey/OneToOneField fields.

 

 Let's take the following example:

 - I initially have a table "Payment" with a "ccy_id" field designating a
 3-letter currency code.
 My model definition looks like:
 {{{
 from django.db import model
 class Payment(models.Model):
 # ...
 ccy_id = models.CharField(max_length=3)

 }}}
 In my python code I can retrieve payments by currency id as follows:
 {{{
 payment_list = list(Payment.objects.filter(ccy_id="USD"))
 }}}

 - Later, I decide to actually create a "Currency" table to hold some
 information about currencies.
 And I also decide to define a foreign key constraint from "Payment" to
 "Currency".
 My model now looks like:
 {{{
 from django.db import model
 class Currency(models.Model):
 ccy_id = models.CharField(max_length=3, primary_key=True)
 #...
 class Payment(models.Model):
 # ...
 ccy = models.ForeignKey(Currency, to_field="ccy_id",
 db_column="ccy_id")

 }}}
 The problem here is that my existing Python code is broken, because
 "ccy_id" is not accepted anymore as kwarg for "Payment" queries.[[BR]]
 Django now only accepts "ccy" instead.

 

 Based on the principle that defining things like foreign keys should only
 add functionality (and not remove any) it seems quite important that on
 top of the field names queries also support attribute name kwargs.[[BR]]
 [[BR]]
 Looking at the code, I can see two ways of achieving this.[[BR]]
 In both cases, the implementation of this feature is pretty small and
 fully backward-compatible:[[BR]]
 [[BR]]
 - The first way is to register fields in options.Option against both their
 name and attname if these differ (SVN diff against trunk below)
 {{{
 Index: django/db/models/options.py
 ===
 --- django/db/models/options.py (revision 10924)
 +++ django/db/models/options.py (working copy)
 @@ -329,6 +329,8 @@
  cache[f.name] = (f, model, True, True)
  for f, model in self.get_fields_with_model():
  cache[f.name] = (f, model, True, False)
 +if f.attname != f.name:
 +cache[f.attname] = (f, model, True, False)
  if self.order_with_respect_to:
  cache['_order'] = OrderWrt(), None, True, False
  if app_cache_ready():
 }}}
 [[BR]]
 - The second way is at query level to always enable a logic currently
 marked as a hack that looks at attname if no field is found with the
 requested name (SVN diff against trunk below)
 {{{
 Index: django/db/models/sql/query.py
 ===
 --- django/db/models/sql/query.py   (revision 10924)
 +++ django/db/models/sql/query.py   (working copy)
 @@ -1678,8 +1678,7 @@
  self.used_aliases = used_aliases

  def setup_joins(self, names, opts, alias, dupe_multis,
 allow_many=True,
 -allow_explicit_fk=False, can_reuse=None, negate=False,
 -process_extras=True):
 +can_reuse=None, negate=False, process_extras=True):
  """
  Compute the necessary table joins for the passage through the
 fields
  given in 'names'. 'opts' is the Options class for the current
 model
 @@ -1715,10 +1714,7 @@
  field, model, direct, m2m = opts.get_field_by_name(name)
  except FieldDoesNotExist:
  for f in opts.fields:
 -if allow_explicit_fk and name == f.attname:
 -# XXX: A hack to allow foo_id to work in values()
 for
 -# backwards compatibility purposes. If we dropped
 that
 -# feature, this could be removed.
 +if name == f.attname:
  field, model, direct, m2m =
 opts.get_field_by_name(f.name)
  break
  else:
 @@ -2026,8 +2022,7 @@
  try:
  for name in field_names:
  field, target, u2, joins, u3, u4 = self.setup_joins(
 -name.split(LOOKUP_SEP), opts, alias, False,
 allow_m2m,
 - 

[Django] #11266: ForeignKey/OneToOneField attribute names should be valid kwargs in queries

2009-06-05 Thread Django
#11266: ForeignKey/OneToOneField attribute names should be valid kwargs in 
queries
---+
 Reporter:  dstora |   Owner:  
nobody
   Status:  new|   Milestone:   
 
Component:  Database layer (models, ORM)   | Version:  
1.0   
 Keywords:  foreign key ForeignKey OneToOneField query filter  |   Stage:  
Unreviewed
Has_patch:  1  |  
---+
 Currently, only the field names are available as kwargs for queries.[[BR]]
 However, it makes (even more) sense that attribute names are supported too
 for !ForeignKey/OneToOneField fields.

 

 Let's take the following example:

 - I initially have a table "Payment" with a "ccy_id" field designating a
 3-letter currency code.
 My model definition looks like:
 {{{
 from django.db import model
 class Payment(models.Model):
 # ...
 ccy_id = models.CharField(max_length=3)

 }}}
 In my python code I can retrieve payments by currency id as follows:
 {{{
 payment_list = list(Payment.objects.filter(ccy_id="USD"))
 }}}

 - Later, I decide to actually create a "Currency" table to hold some
 information about currencies.
 And I also decide to define a foreign key constraint from "Payment" to
 "Currency".
 My model now looks like:
 {{{
 from django.db import model
 class Currency(models.Model):
 ccy_id = models.CharField(max_length=3, primary_key=True)
 #...
 class Payment(models.Model):
 # ...
 ccy = models.ForeignKey(Currency, to_field="ccy_id",
 db_column="ccy_id")

 }}}
 The problem here is that my existing Python code is broken, because
 "ccy_id" is not accepted anymore as kwarg for "Payment" queries.[[BR]]
 Django now only accepts "ccy" instead.

 

 Based on the principle that defining things like foreign keys should only
 add functionality (and not remove any) it seems quite important that on
 top of the field names queries also support attribute name kwargs.[[BR]]
 [[BR]]
 Looking at the code, I can see two ways of achieving this.[[BR]]
 In both cases, the implementation of this feature is pretty small and
 fully backward-compatible:[[BR]]
 [[BR]]
 - The first way is to register fields in options.Option against both their
 name and attname if these differ (SVN diff against trunk below)
 {{{
 Index: django/db/models/options.py
 ===
 --- django/db/models/options.py (revision 10924)
 +++ django/db/models/options.py (working copy)
 @@ -329,6 +329,8 @@
  cache[f.name] = (f, model, True, True)
  for f, model in self.get_fields_with_model():
  cache[f.name] = (f, model, True, False)
 +if f.attname != f.name:
 +cache[f.attname] = (f, model, True, False)
  if self.order_with_respect_to:
  cache['_order'] = OrderWrt(), None, True, False
  if app_cache_ready():
 }}}
 [[BR]]
 - The second way is at query level to always enable a logic currently
 marked as a hack that looks at attname if no field is found with the
 requested name (SVN diff against trunk below)
 {{{
 Index: django/db/models/sql/query.py
 ===
 --- django/db/models/sql/query.py   (revision 10924)
 +++ django/db/models/sql/query.py   (working copy)
 @@ -1678,8 +1678,7 @@
  self.used_aliases = used_aliases

  def setup_joins(self, names, opts, alias, dupe_multis,
 allow_many=True,
 -allow_explicit_fk=False, can_reuse=None, negate=False,
 -process_extras=True):
 +can_reuse=None, negate=False, process_extras=True):
  """
  Compute the necessary table joins for the passage through the
 fields
  given in 'names'. 'opts' is the Options class for the current
 model
 @@ -1715,10 +1714,7 @@
  field, model, direct, m2m = opts.get_field_by_name(name)
  except FieldDoesNotExist:
  for f in opts.fields:
 -if allow_explicit_fk and name == f.attname:
 -# XXX: A hack to allow foo_id to work in values()
 for
 -# backwards compatibility purposes. If we dropped
 that
 -# feature, this could be removed.
 +if name == f.attname:
  field, model, direct, m2m =
 opts.get_field_by_name(f.name)
  break
  else:
 @@ -2026,8 +2022,7 @@
  try:
  for name in field_names:
  field, target, u2, joins, u3, u4 = self.setup_joins(
 -name.split(LOOKUP_SEP), opts, alias, False,
 allow_m2m,
 - 

Re: [Django] #8193: `__import__(mod, {}, {}, [''])` causes double import of modules ('module' and 'module' + '.')

2009-06-05 Thread Django
#8193: `__import__(mod, {}, {}, [''])` causes double import of modules ('module'
and 'module' + '.')
+---
  Reporter:  i_i| Owner:  jacob 
Status:  closed | Milestone:  1.1   
 Component:  Uncategorized  |   Version:  SVN   
Resolution:  fixed  |  Keywords:  import
 Stage:  Accepted   | Has_patch:  1 
Needs_docs:  0  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Comment (by akaihola):

 Replying to [comment:38 jacob]:
 > (In [10088]) Fixed #8193: all dynamic imports in Django are now done
 correctly. I know this because Brett Cannon borrowed the time machine and
 brought Python 2.7's '`importlib` back for inclusion in Django. Thanks for
 the patch-from-the-future, Brett!

 See #11264 for a small problem this changeset introduced.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11260: File based cache not very efficient with large amounts of cached files

2009-06-05 Thread Django
#11260: File based cache not very efficient with large amounts of cached files
---+
  Reporter:  anteater_sa   | Owner:  nobody  
Status:  new   | Milestone:  1.2 
 Component:  Cache system  |   Version:  1.0 
Resolution:|  Keywords:  filebased file cache
 Stage:  Unreviewed| Has_patch:  1   
Needs_docs:  1 |   Needs_tests:  1   
Needs_better_patch:  0 |  
---+
Changes (by dc):

  * needs_docs:  0 => 1
  * needs_tests:  0 => 1
  * milestone:  1.1 => 1.2

Comment:

 1.1 is at a feature freeze right now so moving to 1.2.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11194: Saving proxy model with raw=True gives UnboundLocalError 'record_exists'

2009-06-05 Thread Django
#11194: Saving proxy model with raw=True gives UnboundLocalError 'record_exists'
---+
  Reporter:  wardi | Owner:  nobody 
  
Status:  new   | Milestone:  1.1
  
 Component:  Database layer (models, ORM)  |   Version:  1.1-beta-1 
  
Resolution:|  Keywords:  proxy 
model serialization
 Stage:  Unreviewed| Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  1  
  
Needs_better_patch:  1 |  
---+
Changes (by dc):

  * keywords:  record_exists db import => proxy model serialization
  * component:  Uncategorized => Database layer (models, ORM)
  * summary:  django.db.models.base.py: UnboundLocalError: local variable
  'record_exists' referenced before assignment =>
  Saving proxy model with raw=True gives
  UnboundLocalError 'record_exists'

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #11265: ForeignKey/OneToOneField should support user-defined id attribute name

2009-06-05 Thread Django
#11265: ForeignKey/OneToOneField should support user-defined id attribute name
-+--
 Reporter:  dstora   |   Owner:  nobody
   Status:  new  |   Milestone:
Component:  Database layer (models, ORM) | Version:  1.0   
 Keywords:  foreign key ForeignKey OneToOneField id  |   Stage:  Unreviewed
Has_patch:  1|  
-+--
 Currently, when defining a !ForeignKey/OneToOneField field XXX, Django
 automatically defines a XXX_id attribute to store the id value.[[BR]]
 However, it is sometimes desirable to decide of the name as XXX_id may not
 be the most appropriate.

 

 Let's take the following example:

 - I initially have a table "Payment" with a "ccy_code" field designating a
 3-letter currency code.
 My model definition looks like:
 {{{
 from django.db import model
 class Payment(models.Model):
 # ...
 ccy_code = models.CharField(max_length=3)

 }}}
 In my python code I refer to the currency code as follows:
 {{{
 p = Payment()
 #...
 print p.ccy_code

 }}}

 - Later, I decide to actually create a "Currency" table to hold some
 information about currencies.
 And I also decide to define a foreign key constraint from "Payment" to
 "Currency".
 My model now looks like:
 {{{
 from django.db import model
 class Currency(models.Model):
 ccy_code = models.CharField(max_length=3, primary_key=True)
 #...
 class Payment(models.Model):
 # ...
 ccy = models.ForeignKey(Currency, to_field="ccy_code",
 db_column="ccy_code")

 }}}
 The problem here is that my existing Python code is broken, because
 "ccy_code" is not defined anymore for "Payment".
 Django has instead define a "ccy_id" attribute.

 

 Based on the principle that defining things like foreign keys should only
 add functionality (and not remove any) it seems quite important to me that
 one can choose the id attribute name.[[BR]]
 [[BR]]
 This can be achieved by adding an optional keyword argument to
 !ForeignKey/OneToOneField constructors (here I decided to call it
 "id_attr_name").[[BR]]
 The implementation of this feature is pretty small and fully backward-
 compatible.[[BR]]
 Here is the SVN diff against trunk:
 {{{
 Index: related.py
 ===
 --- related.py  (revision 10924)
 +++ related.py  (working copy)
 @@ -660,6 +660,7 @@
  class ForeignKey(RelatedField, Field):
  empty_strings_allowed = False
  def __init__(self, to, to_field=None, rel_class=ManyToOneRel,
 **kwargs):
 +self.__id_attr_name = kwargs.pop('id_attr_name', None)
  try:
  to_name = to._meta.object_name.lower()
  except AttributeError: # to._meta doesn't exist, so it must be
 RECURSIVE_RELATIONSHIP_CONSTANT
 @@ -679,7 +680,10 @@
  self.db_index = True

  def get_attname(self):
 -return '%s_id' % self.name
 +if self.__id_attr_name:
 +return self.__id_attr_name
 +else:
 +return '%s_id' % self.name

  def get_validator_unique_lookup_type(self):
  return '%s__%s__exact' % (self.name,
 self.rel.get_related_field().name)

 }}}

 In my example, I could then define my model like:
 {{{
 from django.db import model
 class Currency(models.Model):
 ccy_code = models.CharField(max_length=3, primary_key=True)
 #...
 class Payment(models.Model):
 # ...
 ccy = models.ForeignKey(Currency, to_field="ccy_code",
 db_column="ccy_code", id_attr_name="ccy_code")

 }}}

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11264: "from django.db import models" clobbered in functions inside __init__.py of installed apps

2009-06-05 Thread Django
#11264: "from django.db import models" clobbered in functions inside 
__init__.py of
installed apps
-+--
  Reporter:  akaihola| Owner:  nobody   
Status:  new | Milestone:   
 Component:  Core framework  |   Version:  SVN  
Resolution:  |  Keywords:  importing
 Stage:  Unreviewed  | Has_patch:  0
Needs_docs:  0   |   Needs_tests:  0
Needs_better_patch:  0   |  
-+--
Comment (by akaihola):

 The issue this causes in Satchmo was reported in a
 [http://groups.google.com/group/satchmo-
 users/browse_thread/thread/bb2b8fe59e72a834 thread] on the Satchmo users
 Google Group.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #2723: yes/no option for BooleanField

2009-06-05 Thread Django
#2723: yes/no option for BooleanField
--+-
  Reporter:  Gary Wilson   | Owner:  
shanx   
Status:  assigned | Milestone:  

 Component:  django.contrib.admin |   Version:  SVN 

Resolution:   |  Keywords:  
nfa-someday, sprintdec01, sprint-pycon08
 Stage:  Accepted | Has_patch:  1   

Needs_docs:  0|   Needs_tests:  0   

Needs_better_patch:  1|  
--+-
Comment (by beer):

 Where is difference between TypedChoiceField(coerce=bool, choices=((False,
 'No'), (True, 'Yes')), widget=forms.RadioSelect) and this?

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #11264: "from django.db import models" clobbered in functions inside __init__.py of installed apps

2009-06-05 Thread Django
#11264: "from django.db import models" clobbered in functions inside 
__init__.py of
installed apps
-+--
  Reporter:  akaihola| Owner:  nobody   
Status:  new | Milestone:   
 Component:  Core framework  |   Version:  SVN  
Resolution:  |  Keywords:  importing
 Stage:  Unreviewed  | Has_patch:  0
Needs_docs:  0   |   Needs_tests:  0
Needs_better_patch:  0   |  
-+--
Changes (by akaihola):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 Replying to [ticket:11264 akaihola]:

 Messed up the assertion error -- for `myapp` it's of course
 {{{
 AssertionError:
   models is 
   instead of django.db.models
 }}}

 So what happens is that inside the function `models` points to the app's
 own `models.py` instead of `django.db.models`.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #11264: "from django.db import models" clobbered in functions inside __init__.py of installed apps

2009-06-05 Thread Django
#11264: "from django.db import models" clobbered in functions inside 
__init__.py of
installed apps
+---
 Reporter:  akaihola|   Owner:  nobody
   Status:  new |   Milestone:
Component:  Core framework  | Version:  SVN   
 Keywords:  importing   |   Stage:  Unreviewed
Has_patch:  0   |  
+---
 If an app `myapp` has the following `__init__.py`:

 {{{
 from django.db import models
 def myfunc():
 assert models.__package__ == 'django.db.models', (
 'models is %r instead of django.db.models' % models)
 }}}

 then calling `myapp.myfunc()` throws:

 {{{
 AssertionError:
   models is 
   instead of django.db.models
 }}}

 This happens only if
  * `myapp` is in INSTALLED_APPS
  * `myfunc` is in `myapp/__init__.py`, not some other module in it
  * Django is r10088 or later (thanks, git bisect)

 This breaks at least Satchmo from a few months back for me, probably trunk
 too.

 r10088 claims to have fixed all dynamic imports in Django by backporting
 `importlib` from Python 2.7.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---