Re: ImageField not deleted while changing
As far as I know, you should implement the file deletion by yourself. You should code it on the Models delete function. preserving the default behaviour. here is a link to some read: http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods How you do the file deletion is just pure python code further on. On Sat, Feb 26, 2011 at 10:12 PM, galago wrote: > d. Is it my fault or Django is designed not to delete it (if so, how to > delete old fil -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to reduce DB queries?
Models: class Technology(models.Model): name = models.CharField(max_length=100, unique=True) slug = models.SlugField(max_length=100, unique=True) class Site(models.Model): name = models.CharField(max_length=100, unique=True) slug = models.SlugField(max_length=100, unique=True) technology = models.ManyToManyField(Technology, blank=True, null=True) Views: def portfolio(request, page=1): sites_list = Site.objects.select_related('technology').only('technology__name', 'name', 'slug',) return render_to_response('portfolio.html', {'sites':sites_list,}, context_instance=RequestContext(request)) Template: {% for site in sites %} {{ site.name }}, {% for tech in site.technology.all %} {{ tech.name }} {% endfor %} {% endfor %} But in that example each site makes 1 additional query to get technology list. Is there any way to make it in 1 query somehow? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ImageField not deleted while changing
Borislav is right, although it seems to me that overriding the model's save method would be more appropriate in Your case. On the other hand, You really should think twice before doing so. There's actually a good reason for django orm not to delete the actual file after the corresponding FileField had been changed or deleted. Your models' edition/deletion is usually handled in db transactions that are rolled back when something goes wrong and unfortunately there's no way to undo a file's deletion... Perhaps it's better to periodically run a script that deletes orphaned files. 2011/2/27 Borislav Petrović > As far as I know, you should implement the file deletion by yourself. You > should code it on the Models delete function. preserving the default > behaviour. > here is a link to some read: > http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods > > How you do the file deletion is just pure python code further on. > > > > On Sat, Feb 26, 2011 at 10:12 PM, galago wrote: > >> d. Is it my fault or Django is designed not to delete it (if so, how to >> delete old fil > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
mistake in admin home page
Please help me, why do I get such a form of admin home page (after autentification): http://www.google.com/url?sa=D&q=https://docs.google.com/leaf%3Fid%3D0B5W4njXO9ND_YmY0ZGQ4NTktZWZiZC00MzU3LWI5ZWEtYTFmM2JkODY5YmEy%26hl%3Den%26authkey%3DCMCK6uQG -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
error # 1 I can't understand at all, error # 2 is because of errors in urls.py files (project level and/or application level), but I cannot find them exactly. Please help On 26 фев, 21:58, vladimir wrote: > 1. Studying example in "The Definite Guide to Django. 2nd ed. > A.Holovaty, J.Kaplan-Moss" I have got impropper form of admin home > page (after > authorisation):https://docs.google.com/leaf?id=0B5W4njXO9ND_YmY0ZGQ4NTktZWZiZC00MzU3... > 2. Studying example (CMS) in "Python Web Development with Django. > J.Forcier, P.Bissex, W.Chun" I have got an > error:https://docs.google.com/leaf?id=0B5W4njXO9ND_Mzg1M2U0ZGItYzZiMS00Y2Qx... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
error #1: seems that the browser is not able to load static resources ( css ). If you had firebug try to check the "net->All" panel for errors Stefano 2011/2/27 veva...@yandex.ru : > error # 1 I can't understand at all, > error # 2 is because of errors in urls.py files (project level and/or > application level), but I cannot find them exactly. Please help > > On 26 фев, 21:58, vladimir wrote: >> 1. Studying example in "The Definite Guide to Django. 2nd ed. >> A.Holovaty, J.Kaplan-Moss" I have got impropper form of admin home >> page (after >> authorisation):https://docs.google.com/leaf?id=0B5W4njXO9ND_YmY0ZGQ4NTktZWZiZC00MzU3... >> 2. Studying example (CMS) in "Python Web Development with Django. >> J.Forcier, P.Bissex, W.Chun" I have got an >> error:https://docs.google.com/leaf?id=0B5W4njXO9ND_Mzg1M2U0ZGItYzZiMS00Y2Qx... > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to reduce DB queries?
Take a look to : http://docs.djangoproject.com/en/1.2/ref/models/querysets/#select-related and http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#regroup Stefano 2011/2/27 galago : > Models: > class Technology(models.Model): > name = models.CharField(max_length=100, unique=True) > slug = models.SlugField(max_length=100, unique=True) > class Site(models.Model): > name = models.CharField(max_length=100, unique=True) > slug = models.SlugField(max_length=100, unique=True) > technology = models.ManyToManyField(Technology, blank=True, null=True) > Views: > def portfolio(request, page=1): > sites_list = > Site.objects.select_related('technology').only('technology__name', 'name', > 'slug',) > return render_to_response('portfolio.html', {'sites':sites_list,}, > context_instance=RequestContext(request)) > Template: > {% for site in sites %} > > {{ site.name }}, > {% for tech in site.technology.all %} > {{ tech.name }} > {% endfor %} > > {% endfor %} > But in that example each site makes 1 additional query to get technology > list. Is there any way to make it in 1 query somehow? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to reduce DB queries?
I use select_related(). How to apply it with regroup? I haven't use it before. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
1) firebug shows nothing in "net->all" panel, 2) the same result is in Firefox 3.6.13, Internet Explorer 8, Google Chrome -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to reduce DB queries?
In template in main loop I want to display all technologies assigned to the each site. Technologies are assigned by m2m relation. So I run subloop as You can see in code above. I want to reduce the number of queries executed by those subqueries. I want to know, if there is a better way to do this. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
nothing ? is it enabled ? Please indicate: - django version - the value of MEDIA_ROOT, MEDIA_URL, ADMIN_MEDIA_PREFIX - urls.py 2011/2/27 Vladimir : > 1) firebug shows nothing in "net->all" panel, 2) the same result is in > Firefox 3.6.13, Internet Explorer 8, Google Chrome > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
Django 1.2.3, in settings.py I have not edit this values: MEDIA_ROOT = '' MEDIA_URL = '' ADMIN_MEDIA_PREFIX = '/media/' urls.py: from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Example: # (r'^mysite/', include('mysite.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: (r'^admin/', include(admin.site.urls)), ) firebug "net->all" shows errors in GET base.css and GET dashboard.css: Traceback (most recent call last): File "C:\Python27\lib\site-packages\django\core\servers \basehttp.py", line 280, in run self.result = application(self.environ, self.start_response) File "C:\Python27\lib\site-packages\django\core\servers \basehttp.py", line 709, in __call__ mime_type = mimetypes.guess_type(file_path)[0] File "C:\Python27\lib\mimetypes.py", line 294, in guess_type init() File "C:\Python27\lib\mimetypes.py", line 355, in init db.read_windows_registry() File "C:\Python27\lib\mimetypes.py", line 259, in read_windows_registry for ctype in enum_types(mimedb): File "C:\Python27\lib\mimetypes.py", line 249, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x! UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128) What does it mean? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to reduce DB queries?
Actually, select_related won't help You with m2m fields. As it's written in docs linked by s.apostolico, it only works with ForeignKeys... As far as I know, there's no way to avoid the extra query using django's orm. 2011/2/27 galago > In template in main loop I want to display all technologies assigned to the > each site. Technologies are assigned by m2m relation. So I run subloop as > You can see in code above. I want to reduce the number of queries executed > by those subqueries. I want to know, if there is a better way to do this. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Browsing through media files on remote machine
On Feb 27, 1:01 am, Borislav Petrović wrote: > Hello, > > Is there an app, or a suggestion on how to browse through media > files on a remote machine? > > I have a setup that would include two separate machines one from a web > hosting for my django site and another that would host media files. I need > to be able to browse and select files from django admin and save their paths > to a database field so they can be served on the web page. No uploading > needed. You need to set MEDIA_PATH =" (IP address or URL) " in setting.py file. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to reduce DB queries?
Artur is right, I did not see that you use m2m. S. 2011/2/27 galago : > In template in main loop I want to display all technologies assigned to the > each site. Technologies are assigned by m2m relation. So I run subloop as > You can see in code above. I want to reduce the number of queries executed > by those subqueries. I want to know, if there is a better way to do this. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
seems that django is not able to decode the .css files try to open /contrib/admin/media/css/base.css with notepad and check it's content S. 2011/2/27 Vladimir : > Django 1.2.3, > > in settings.py I have not edit this values: > MEDIA_ROOT = '' > MEDIA_URL = '' > ADMIN_MEDIA_PREFIX = '/media/' > > urls.py: > from django.conf.urls.defaults import * > > # Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('', > # Example: > # (r'^mysite/', include('mysite.foo.urls')), > > # Uncomment the admin/doc line below to enable admin > documentation: > (r'^admin/doc/', include('django.contrib.admindocs.urls')), > > # Uncomment the next line to enable the admin: > (r'^admin/', include(admin.site.urls)), > ) > > firebug "net->all" shows errors in GET base.css and GET > dashboard.css: > Traceback (most recent call last): > > File "C:\Python27\lib\site-packages\django\core\servers > \basehttp.py", line 280, in run > self.result = application(self.environ, self.start_response) > > File "C:\Python27\lib\site-packages\django\core\servers > \basehttp.py", line 709, in __call__ > mime_type = mimetypes.guess_type(file_path)[0] > > File "C:\Python27\lib\mimetypes.py", line 294, in guess_type > init() > > File "C:\Python27\lib\mimetypes.py", line 355, in init > db.read_windows_registry() > > File "C:\Python27\lib\mimetypes.py", line 259, in > read_windows_registry > for ctype in enum_types(mimedb): > > File "C:\Python27\lib\mimetypes.py", line 249, in enum_types > ctype = ctype.encode(default_encoding) # omit in 3.x! > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position > 0: ordinal not in range(128) > > What does it mean? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
/* DJANGO Admin styles */ body { margin: 0; padding: 0; font-size: 12px; font-family: "Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; color: #333; background: #fff; } /* LINKS */ a:link, a:visited { color: #5b80b2; text-decoration: none; } a:hover { color: #036; } a img { border: none; } a.section:link, a.section:visited { color: white; text-decoration: none; } /* GLOBAL DEFAULTS */ p, ol, ul, dl { margin: .2em 0 .8em 0; } p { padding: 0; line-height: 140%; } h1,h2,h3,h4,h5 { font-weight: bold; } h1 { font-size: 18px; color: #666; padding: 0 6px 0 0; margin: 0 0 .2em 0; } h2 { font-size: 16px; margin: 1em 0 .5em 0; } h2.subhead { font-weight: normal; margin-top: 0; } h3 { font-size: 14px; margin: .8em 0 .3em 0; color: #666; font-weight: bold; } h4 { font-size: 12px; margin: 1em 0 .8em 0; padding-bottom: 3px; } h5 { font-size: 10px; margin: 1.5em 0 .5em 0; color: #666; text-transform: uppercase; letter-spacing: 1px; } ul li { list-style-type: square; padding: 1px 0; } ul.plainlist { margin-left: 0 !important; } ul.plainlist li { list-style-type: none; } li ul { margin-bottom: 0; } li, dt, dd { font-size: 11px; line-height: 14px; } dt { font-weight: bold; margin-top: 4px; } dd { margin-left: 0; } form { margin: 0; padding: 0; } fieldset { margin: 0; padding: 0; } blockquote { font-size: 11px; color: #777; margin-left: 2px; padding-left: 10px; border-left: 5px solid #ddd; } code, pre { font-family: "Bitstream Vera Sans Mono", Monaco, "Courier New", Courier, monospace; background: inherit; color: #666; font-size: 11px; } pre.literal-block { margin: 10px; background: #eee; padding: 6px 8px; } code strong { color: #930; } hr { clear: both; color: #eee; background-color: #eee; height: 1px; border: none; margin: 0; padding: 0; font-size: 1px; line-height: 1px; } /* TEXT STYLES & MODIFIERS */ .small { font-size: 11px; } .tiny { font-size: 10px; } p.tiny { margin-top: -2px; } .mini { font-size: 9px; } p.mini { margin-top: -3px; } .help, p.help { font-size: 10px !important; color: #999; } p img, h1 img, h2 img, h3 img, h4 img, td img { vertical-align: middle; } .quiet, a.quiet:link, a.quiet:visited { color: #999 !important; font-weight: normal !important; } .quiet strong { font-weight: bold !important; } .float-right { float: right; } .float-left { float: left; } .clear { clear: both; } .align-left { text-align: left; } .align-right { text-align: right; } .example { margin: 10px 0; padding: 5px 10px; background: #efefef; } .nowrap { white-space: nowrap; } /* TABLES */ table { border-collapse: collapse; border-color: #ccc; } td, th { font-size: 11px; line-height: 13px; border-bottom: 1px solid #eee; vertical-align: top; padding: 5px; font-family: "Lucida Grande", Verdana, Arial, sans-serif; } th { text-align: left; font-size: 12px; font-weight: bold; } thead th, tfoot td { color: #666; padding: 2px 5px; font-size: 11px; background: #e1e1e1 url(../img/admin/nav-bg.gif) top left repeat- x; border-left: 1px solid #ddd; border-bottom: 1px solid #ddd; } tfoot td { border-bottom: none; border-top: 1px solid #ddd; } thead th:first-child, tfoot td:first-child { border-left: none !important; } thead th.optional { font-weight: normal !important; } fieldset table { border-right: 1px solid #eee; } tr.row-label td { font-size: 9px; padding-top: 2px; padding-bottom: 0; border-bottom: none; color: #666; margin-top: -1px; } tr.alt { background: #f6f6f6; } .row1 { background: #EDF3FE; } .row2 { background: white; } /* SORTABLE TABLES */ thead th a:link, thead th a:visited { color: #666; display: block; } table thead th.sorted { background-position: bottom left !important; } table thead th.sorted a { padding-right: 13px; } table thead th.ascending a { background: url(../img/admin/arrow-down.gif) right .4em no-repeat; } table thead th.descending a { background: url(../img/admin/arrow-up.gif) right .4em no-repeat; } /* ORDERABLE TABLES */ table.orderable tbody tr td:hover { cursor: move; } table.orderable tbody tr td:first-child { padding-left: 14px; background-image: url(../img/admin/nav-bg-grabber.gif); background-repeat: repeat-y; } table.orderable-initalized .order-cell, body>tr>td.order-cell { display: none; } /* FORM DEFAULTS */ input, textarea, select, .form-row p { margin: 2px 0; padding: 2px 3px; vertical-align: middle; font-family: "Lucida Grande", Verdana, Arial, sans-serif; fo
Re: admin home page
is it a good idea to delete Django from Python27/Lib/site-packages and install Django-1.2.5 ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to reduce DB queries?
Could you do a ManyToMany relationship through an intermediary model, and then query the intermediary using select related? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
I use virtualenv so can test my app with multiple django version easy. http://pypi.python.org/pypi/virtualenv S. 2011/2/27 Vladimir : > is it a good idea to delete Django from Python27/Lib/site-packages and > install Django-1.2.5 ? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
I have installed Django-1.2.5. No effect. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: mistake in admin home page
On Sun, Feb 27, 2011 at 5:46 AM, vladimir wrote: > Please help me, why do I get such a form of admin home page (after > autentification): > > http://www.google.com/url?sa=D&q=https://docs.google.com/leaf%3Fid%3D0B5W4njXO9ND_YmY0ZGQ4NTktZWZiZC00MzU3LWI5ZWEtYTFmM2JkODY5YmEy%26hl%3Den%26authkey%3DCMCK6uQG Your browser's not finding the admin media location to load the css. Look at the docs for ADMIN_MEDIA_PREFIX. (I think that's the one...) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Query Builder forgets annotations
On Sat, Feb 26, 2011 at 12:39 PM, Pascal Germroth wrote: > It seems the query builder forgets annotations when dealing with joins: > > Not in my experience. > > I have this model with Postgresql, Django 1.3 alpha 1 (SVN rev. 15659): > I don't quite understand that Django rev spec. r15659 is quite recent (less than two days ago), but an SVN checkout should be reporting the version an 1.3 beta, not 1.3 alpha. What are you running exactly? > > class Corporation(Model): >uuid = UuidField(primary_key=True) > > class Branch(Model): >uuid = UuidField(primary_key=True) >corporation = ForeignKey(Corporation, related_name='branches') > I don't know exactly what UuidField here is so for my test I change this to: class Corporation(models.Model): uuid = models.CharField(max_length=14, primary_key=True) def __unicode__(self): return u'Corp %s with %d branches' % (self.uuid, self.branches.count()) class Branch(models.Model): uuid = models.CharField(max_length=14, primary_key=True) corporation = models.ForeignKey(Corporation, related_name='branches') > Now I want to retrieve the corporations ordered by the number of their > branches: > Corporation.objects.annotate(x=Count('branches')).order_by('x') > > Which fails with: > FieldError: Cannot resolve keyword 'x' into field. Choices are: > branches, uuid in /django/db/models/sql/query.py in setup_joins, line 1236 > > Not for me: python manage.py shell Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> import django >>> django.get_version() u'1.3 beta 1 SVN-15659' >>> from ttt.models import Corporation >>> from django.db.models import Count >>> Corporation.objects.annotate(x=Count('branches')).order_by('x') [, , ] This > Corporation.objects.annotate(x=Count('branches')) > yields > SELECT corporation.uuid, COUNT(branch.uuid) AS x FROM corporation LEFT > OUTER JOIN branch ON (corporation.uuid = branch.corporation_id) GROUP BY > corporation.uuid, corporation.uuid > > and executing this query manually, with `ORDER BY x` added, gives me > what I want. > > Is this a django bug, or by design? > > In my test, the ORM query you show generates the above SQL plus the requested order by: >>> from django.db import connection >>> connection.queries[0]['sql'] 'SELECT "ttt_corporation"."uuid", COUNT("ttt_branch"."uuid") AS "x" FROM "ttt_corporation" LEFT OUTER JOIN "ttt_branch" ON ("ttt_corporation"."uuid" = "ttt_branch"."corporation_id") GROUP BY "ttt_corporation"."uuid", "ttt_corporation"."uuid" ORDER BY "x" ASC LIMIT 21' Something other than what you have shown (and I don't think it is the missing UuidField definition) is coming into play here to produce the results you are seeing. I have no idea what that is though. Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Query Builder forgets annotations
Hi, >> It seems the query builder forgets annotations when dealing with joins: > Not in my experience. Yeah I experimented further and it wasn't actually a problem with /that/ part of the query (well, it changed when I added/removed the order_by, but the actual cause was some interference once it was evaluated). I'll try to create a minimal example. -- Pascal Germroth -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Some cache problems
1. I'm wondering if I can delete a cached content made in template cache. I want to delete it from my view. I have in my template {% cache 500 cache_name sites.number %} Is it possible to delete all "cache_name" cached content within the view, for example when some action is made? 2. I want to use per-vie cache ( http://docs.djangoproject.com/en/dev//topics/cache/#the-per-view-cache). I do all what is described, but when I call: @cache_page(3600, cache="cache_name") I get error: Exception Type: ValueError Exception Value: need more than 1 value to unpack What I want to achieve is to cache all my template block or view and have a possibility to delete all cache connected with it when some actions are made. Pagination is included -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to check if string is in Hebrew
Hebrew is within the unicode range 0x590 to 0x5ff. I tried if lang_string[0] >= u'0x590' and lang_string[0] <= u'0x5ff': but it does not seem to work. How do I check if lang_string is in Hebrew or not. Using Python 2.5, Django 1.2 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
ax variables from google using django.auth.openid
I've successfully setup django.auth.openid to do to the login through google, and I see that it will prompt the user for releasing their e- mail. However, I don't see anything available that let's me query the e-mail. Where is that information stored? request.user somewhere? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to get attribute of intermediary model?
Ah yes, that is *much* better. Thank you! Sorry for the delay, forgot to check back on this thread till now. Margie On Feb 17, 2:28 pm, Daniel Roseman wrote: > On Thursday, February 17, 2011 10:06:40 PM UTC, Margie Roginski wrote: > > > Thanks for your reply, Daniel. I didn't give my example specifically > > enough. In my particular case I actually have a handle to the Person > > and actually don't need all the join dates for all the people in that > > group. I just need that person's join date. > > > I can see that it is easy to get all membership info for a given > > group, but I'm guessing that my original solution is the appropriate > > solution for getting the join date for just a single person? > > > Margie > > No, because you're doing a lot of extra selecting and iterating that you > don't need to. You can still do it in a single go: > > Membership.objects.get(person=person, group__name='beatles').join_date > > I often find that apparently difficult queries become a lot simpler if you > approach them from the other direction - from the Membership rather than the > Group, in this instance. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin home page
To Lee Hinde: Thank You. You answered me: Your browser's not finding the admin media location to load the css. Look at the docs for ADMIN_MEDIA_PREFIX. (I think that's the one...) I have looked: ADMIN_MEDIA_PREFIX Default: '/media/' The URL prefix for admin media -- CSS, JavaScript and images used by the Django administrative interface. Make sure to use a trailing slash, and to have this be different from the MEDIA_URL setting (since the same URL cannot be mapped onto two different sets of files). I haven't edit ADMIN_MEDIA_PREFIX = '/media/' in settings.py -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to check if string is in Hebrew
On Sun, Feb 27, 2011 at 6:01 PM, ydjango wrote: > Hebrew is within the unicode range 0x590 to 0x5ff. > > I tried > if lang_string[0] >= u'0x590' and lang_string[0] <= u'0x5ff': > > but it does not seem to work. > > How do I check if lang_string is in Hebrew or not. Using Python 2.5, > Django 1.2 > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > See the ord() function: http://docs.python.org/library/functions.html#ord -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
urls.py usage
2. Studying example (CMS) in "Python Web Development with Django. J.Forcier, P.Bissex, W.Chun" I have got an error: https://docs.google.com/leaf?id=0B5W4njXO9ND_Mzg1M2U0ZGItYzZiMS00Y2Qx... adding detailes. I study CMS project in Chapter 8 in that book. Following authors I wrote: 1) project level cmsproject/urls.py: from django.contrib import admin from django.conf.urls.defaults import * admin.autodiscover() urlpatterns = patterns('', # Uncomment the next line to enable the admin: # (r'^admin/', include(admin.site.urls)), # url(r'^admin/(.*)', admin.site.root), url(r'^admin/(.*)', admin.site.urls), url(r'^cms/', include('cmsproject.cms.urls')), # Example: # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), ) 2) application level cmsproject/cms/urls.py: from django.conf.urls.defaults import * from cms.models import Story from cms.models import Category info_dict = {'queryset': Story.objects.all(), 'template_object_name': 'story'} urlpatterns = patterns('cmsproject.cms.views', url(r'^category/(?P[-\w]+)/$', 'category', name="cms- category"), url(r'^search/$', 'search', name="cms-search"), ) urlpatterns += patterns('django.views.generic.list_detail', url(r'^(?P[-\w]+)/$', 'object_detail', info_dict, name="cms- story"), url(r'^$', 'object_list', info_dict, name="cms-home"), ) error message is: TemplateSyntaxError at /admin/ Caught AlreadyRegistered while rendering: The model Category is already registered I also don't understand why cmsproject/cms/urls.py contains = but not += in the statement urlpatterns = patterns... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Extend admin template without copying the whole template
Hi all, I want to add a language switcher below the breadcrumb to all my django admin pages. Therefore I created templates/admin/base.html in my project. However I don't want to copy the whole original base.html and add my changes - this would defeat the DRY principle and it would be a maintenance nightmare whenever I update to the latest django version. So I tried the obvious: {% extends "admin/base.html" %} {% block breadcrumb %} [old breadcrumb code] [my additional code] {% endblock %} And of course the obvious error happened: The template tries to extend itself. Couldn't the system be smart enough and recognize that it is trying to import itself and then search for another template to extend at the next available template loader in line? As in: Whoops, I'm trying to extend myself when using base.html from the project's file system... ok let's see if I can find admin/base.html in the python path or in the eggs... Is there any other fancy trick or workaround to accomplish this? I believe that enhancing global admin templates should be something that is a very common usecase, isn't it? Best regards, Martin -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Extend admin template without copying the whole template
On Monday, 28 February 2011, Martin Brochhaus wrote: > Hi all, > I want to add a language switcher below the breadcrumb to all my django admin > pages. > Therefore I created templates/admin/base.html in my project. However I don't > want to copy the whole original base.html and add my changes - this would > defeat the DRY principle and it would be a maintenance nightmare whenever I > update to the latest django version. > So I tried the obvious: > {% extends "admin/base.html" %}{% block breadcrumb %}[old breadcrumb code][my > additional code]{% endblock %} > And of course the obvious error happened: The template tries to extend > itself. Couldn't the system be smart enough and recognize that it is trying > to import itself and then search for another template to extend at the next > available template loader in line? As in: Whoops, I'm trying to extend myself > when using base.html from the project's file system... ok let's see if I can > find admin/base.html in the python path or in the eggs... > Is there any other fancy trick or workaround to accomplish this? I believe > that enhancing global admin templates should be something that is a very > common usecase, isn't it? > Best regards,Martin > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > Hi, Martin! If I got your point in right way - May be {{ block.super}} construction will be useful for you. Regards, Alex -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Extend admin template without copying the whole template
Hi Alex, many thanks for your suggestion but I think {{ block.super }} will not help. In order to have a parent template I would first have to write something like {% extends "admin/base.html" %} but this already is not possible because it would mean inheriting itself. Best regards, Martin On Mon, Feb 28, 2011 at 1:41 PM, Alex Boyko wrote: > On Monday, 28 February 2011, Martin Brochhaus > wrote: > > Hi all, > > I want to add a language switcher below the breadcrumb to all my django > admin pages. > > Therefore I created templates/admin/base.html in my project. However I > don't want to copy the whole original base.html and add my changes - this > would defeat the DRY principle and it would be a maintenance nightmare > whenever I update to the latest django version. > > So I tried the obvious: > > {% extends "admin/base.html" %}{% block breadcrumb %}[old breadcrumb > code][my additional code]{% endblock %} > > And of course the obvious error happened: The template tries to extend > itself. Couldn't the system be smart enough and recognize that it is trying > to import itself and then search for another template to extend at the next > available template loader in line? As in: Whoops, I'm trying to extend > myself when using base.html from the project's file system... ok let's see > if I can find admin/base.html in the python path or in the eggs... > > Is there any other fancy trick or workaround to accomplish this? I > believe that enhancing global admin templates should be something that is a > very common usecase, isn't it? > > Best regards,Martin > > > > > > > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > > To post to this group, send email to django-users@googlegroups.com. > > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > > Hi, Martin! > > If I got your point in right way - May be {{ block.super}} > construction will be useful for you. > > Regards, Alex > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
AW: combobox
Thx, i'll give it a shot ;-) . . . . . . . . . . . . . . . . . . . . . . . . . . Patrick Szabo XSLT-Entwickler LexisNexis Marxergasse 25, 1030 Wien mailto:patrick.sz...@lexisnexis.at Tel.: +43 (1) 534 52 - 1573 Fax: +43 (1) 534 52 - 146 -Ursprüngliche Nachricht- Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im Auftrag von Marc DM Gesendet: Freitag, 25. Februar 2011 19:36 An: Django users Betreff: Re: combobox On Feb 25, 11:18 am, "Szabo, Patrick \(LNG-VIE\)" wrote: > Hi, > > I was trying to get "An AJAX Select Widget for Django" > (http://code.djangoproject.com/wiki/AJAXWidgetComboBox) running but i > found out that it doesn't work with newer versions of django (correct me > if I'm wrong.) > > Is there an alternative or a way to make it work with the newest version > ?! If you're using jQuery, you could take a look at the combobox example on the jQueryUI autocomplete page. http://jqueryui.com/demos/autocomplete/#combobox They use the autocomplete widget from jQueryUI and create a basic combobox. The good thing is that the code is all right there and quite easy to understand. So, if it doesn't do EXACTLY what you want, you can modify it. There seems to be no real consensus on how the combobox should work so there are many incompatible versions out there. Try using the jQuery one as a starting point and make what you want. Just my $0.02 Marc DM DjangoMuser -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.