Re: Sample Django AppEngine App
On Sat, Jul 3, 2010 at 8:00 AM, Gath wrote: > Won't it be nice to start first by learning Django! From my experience > Django was not build to run on top of AppEngine. There are alot of > hacks on django to make run on AppEngine that might confuse a > beginner, e.g Django was built to run on relational databases, while > AppEngine applications run on bigtables(datastore) which are not > relational. So i guess it would be nice to first understand the django > ORM before trying to map it to the AppEngine one. > > But having said that, i don't mean it is impossible to write one but i > won't advice that line for a beginner. > Of course, learning Django would be the best start. But there is Django-nonrel ([0]), which adds support for non-relational databases to Django. At the moment there are backends for AppEngine ([1]) and MongoDB. Flo [0]http://www.allbuttonspressed.com/projects/django-nonrel [1] http://www.allbuttonspressed.com/blog/django/2010/01/Native-Django-on-App-Engine -- http://www.d3f3nd3r.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Problem with L10N of DecimalField
For clarification: The output in the admin list view is properly localized. Only the input doesn't work. I'm using Django 1.2.1 and a almost vanilla Django project only with this one test app installed. On 3 Jul., 22:07, Simon Westphahl wrote: > Hi, > > I tried to implement a localized "DecimalField" but it doesn't seem to > work. When entering a decimal number with a German decimal seperator > ( , ) the admin interface tells me to "Enter a number". Is there some > setting/middleware/etc. I overlooked? > > My "settings.py" and test model look something like this: > > ### settings.py ### > [...] > LANGUAGE_CODE = 'de' > USE_I18N = True > USE_L10N = True > [...] > ### > > ### models.py ### > from django.contrib import admin > from django.db import models > > class DecTest(models.Model): > dec = models.DecimalField(max_digits=8, decimal_places=2) > > admin.site.register(DecTest) > ### > > Thanks in advance! > > Regards > Simon -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Problem with (possible bug?) with the random number generator in django/middleware/csrf.py
Hello all I experienced a strange behaviour with my django application when I wanted to deploy and test on my apache instance on my virtual server. I could successfully deploy my application but when I wanted to access any view the browser just took forever to load and it never showed the view. Accessing any non existing view gave the correct debug error view. After a long debugging session I could locate the problem to be in django/middleware/csrf.py. The call which actually took a very long time was the call to randrange(0, _MAX_CSRF_KEY). By playing around in a python session it seems that the call to the system randrange with random.SystemRandom().randrange(0, _MAX_CSRF_KEY) never stops (or doesn't seem to stop in less than 30 minutes) whereas a call to the "normal" randrange with randrange(0, _MAX_CSRF_KEY) happily returns the desired random number. I had to manully set the line "randrange = random.randrange" instead of the if/else logic which checks for the system random generator to make my app work on my virtual host. Now it seems that is not a django problem per se. But I am wondering what I should to with this kind of error as I had to manually fiddle around in the django-code to be able to successfully host my application. In my virtual host I use apache 2.2.15 with python 2.6.5, mod_wsgi 3.2 and django 1.2.1 Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 get a model instance's field var while field's name is a string in template?
i mean i have a model instance m, and m has a field fd. so i can wrote like this in template {{ m.fd }} but, when i got a string s = "fd" how could i do the same as above? thanks for any help... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Problem with L10N of DecimalField
I figured out a way to get it working. ### models.py [...] class DecTest(models.Model): dec = models.DecimalField(max_digits=8, decimal_places=2) class LocalDecForm(forms.ModelForm): dec = forms.DecimalField(max_digits=8, decimal_places=2, localize=True) class Meta: model = DecTest class DecAdmin(admin.ModelAdmin): form = LocalDecForm list_display = ('dec',) [...] ### But is this realy the way it's meant to work? A "DateTimeField" is localized by default ... On 4 Jul., 11:03, Simon Westphahl wrote: > For clarification: The output in the admin list view is properly > localized. Only the input doesn't work. > I'm using Django 1.2.1 and a almost vanilla Django project only with > this one test app installed. > > On 3 Jul., 22:07, Simon Westphahl wrote: > > > > > Hi, > > > I tried to implement a localized "DecimalField" but it doesn't seem to > > work. When entering a decimal number with a German decimal seperator > > ( , ) the admin interface tells me to "Enter a number". Is there some > > setting/middleware/etc. I overlooked? > > > My "settings.py" and test model look something like this: > > > ### settings.py ### > > [...] > > LANGUAGE_CODE = 'de' > > USE_I18N = True > > USE_L10N = True > > [...] > > ### > > > ### models.py ### > > from django.contrib import admin > > from django.db import models > > > class DecTest(models.Model): > > dec = models.DecimalField(max_digits=8, decimal_places=2) > > > admin.site.register(DecTest) > > ### > > > Thanks in advance! > > > Regards > > Simon -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 a model instance's field var while field's name is a string in template?
On Jul 4, 12:01 pm, "David.D" wrote: > i mean > i have a model instance m, and m has a field fd. > so i can wrote like this in template > {{ m.fd }} > > but, when i got a string s = "fd" > > how could i do the same as above? > > thanks for any help... There's no built-in way. A simple custom filter will do the job. @register.filter def field_from_string(instance, fieldname): return getattr(instance, fieldname) Now you can do: {{ m|field_from_string:s }} -- 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-us...@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 a model instance's field var while field's name is a string in template?
It work! Thank you. On Jul 4, 9:30 pm, Daniel Roseman wrote: > On Jul 4, 12:01 pm, "David.D" wrote: > > > i mean > > i have a model instance m, and m has a field fd. > > so i can wrote like this in template > > {{ m.fd }} > > > but, when i got a string s = "fd" > > > how could i do the same as above? > > > thanks for any help... > > There's no built-in way. A simple custom filter will do the job. > > @register.filter > def field_from_string(instance, fieldname): > return getattr(instance, fieldname) > > Now you can do: > > {{ m|field_from_string:s }} > > -- > 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-us...@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.
filtering admin data
hi all; sorry for wasting your preciouse tume. I'm trouble with the following: class A(models.Model): . . . class B(models.Model): . . . a= models.ForeignKey(A) class C(models.Model): . . . b= models.ForeignKey(B) How can i filter data that belongs to an A instance, while editing class C instances, using django Admin? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Different fieldsets in django admin for add and change?
Hello World I wanted to know how to implement different fieldsets for the add and change pages in django admin like a lot of applications do (django-cms for ex) Any help would be much appreciated. -- - Aziz M. Bookwala -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 set initial form field value in the view function?
How set initial form field value in the view function? The initial keyword is great when defining a subclass of Form if you the initial values is ALWAYS the same. What if it varies?...I'm guessing I must set it in the view. How set this initial value in the view? Chris -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
messages framework: disable caching?
Hallöchen! I wonder whether it makes sense to disable caching in responses which used messages from the messages framework. Since they are consumed by displaying them, I don't see a point in letting upsteam caches to cache the page. I added if request._messages.used: add_never_cache_headers(response) to "process_response" of MessageMiddleware and it works nicely for me. Doesn't it make sense to do that always, or at least, by default? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: torsten.bron...@jabber.rwth-aachen.de or http://bronger-jmp.appspot.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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 set initial form field value in the view function?
> The initial keyword is great when defining a subclass of Form if you > the initial values is ALWAYS the same. > > What if it varies?...I'm guessing I must set it in the view. From: http://docs.djangoproject.com/en/1.2/ref/forms/api/#dynamic-initial-values we have: Dynamic initial values¶ Form.initial Use initial to declare the initial value of form fields at runtime. For example, you might want to fill in a username field with the username of the current session. Possibly you could restate your requirement? At least I'm not seeing why fm(initial={'x':variable_name}) won't help you. Or possibly you want to override the __init__ method of the form? Jim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Different fieldsets in django admin for add and change?
On Jul 4, 4:04 pm, Aziz Bookwala wrote: > Hello World > I wanted to know how to implement different fieldsets for the add and change > pages in django admin like a lot of applications do (django-cms for ex) > Any help would be much appreciated. > > -- > - Aziz M. Bookwala You can override the `get_form` and `get_fieldset` methods on the ModelAdmin class. You can see the originals in `django.contrib.admin.options`. Both take an `obj` parameter - if this is None, this is an add view, otherwise it is a change view. -- 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-us...@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.
Debugging Django under wsgi and pydev
Is there a way to run a django app that's being served on the local machine via Apache and mod_wsgi using the integrated debugger in wsgi? I did a few google searches but nothing popped out as being the obvious solution, other than a suggestion from google to run apache httpd -x which I'd take as being a first step towards it but not the actual solution. Thanks, -Doug -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
break/continue for templates
Hi all, there have been at least three threads in this list alone from people asking how to "break" from a for loop in templates, so the following snippet [1] might be useful to some. Leaving aside the "thou shalt not use logic in templates" religious debate, it's interesting in that it is syntactically more powerful than the respective Python statements: you can continue/break not just from the innermost loop but from outer ones too. Here's a small example: {% for key,values in mapping.iteritems %} {% for value in values %} {{ key }}: {{ value }} {% if value|divisibleby:3 %} {{ value }} is divisible by 3 {{ forloop.parentloop|continue }} {% endif %} {% endfor %} {{ key }}: No value divisible by 3 {% endfor %} Given context = {'mapping': dict(a=[1,2,3], c=[2,4,5], b=[3,5,7])}, the output is: a: 1 a: 2 a: 3 3 is divisible by 3 c: 2 c: 4 c: 5 c: No value divisible by 3 b: 3 3 is divisible by 3 Tested (lightly) on Django 1.2 / Python 2.6; please let me know if you hit any bugs or unexpected behavior. Cheers, George [1] http://djangosnippets.org/snippets/2092/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
problems accessing to media.djangoproject.com - perhaps from argentina ?
Hi anone else have had problem with media.djangoproject.com ? /.virtualenvs/site.com/bin# ./easy_install django Searching for django Reading http://pypi.python.org/simple/django/ Reading http://www.djangoproject.com/ Best match: Django 1.2.1 Downloading http://media.djangoproject.com/releases/1.2/Django-1.2.1.tar.gz error: Download error for http://media.djangoproject.com/releases/1.2/Django-1.2.1.tar.gz: [Errno 60] Operation timed out (site.com)macbookpro~/.virtualenvs/site.com/bin# I'm also having problems accessing to www.djangoproject.com ISP: telecentro Regards. Aldo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
django.utils.functional.__proxy__ object
Evening all I've just moved a really old django project of ours over to a new machine, newer python, and newer mysql. I'm using a mentally old version of django, revision 5783. The move has gone tickety boo, we're using nginx instead of lighttpd as well. The only oddity I've got is that in the admin section the names of the applications in the project are showing up as They all work, in fact, the whole site works, but as the names of the apps are all mashed up I can't hand it over to the client. Has anyone got any ideas what could be causing this? As I said, its the same django_src folder, the same project code, just newer python, mysql, and nginx instead of lighttpd. Please don't say upgrade, the client won't pay for it and I can't do it as a freebie as I'm all freebied out. Any help is greatly appreciated as always. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
db_schema support was broken by Debian upgrade: 'class Meta' got invalid attribute(s): db_schema
During an update of Debian ("squeeze/sid") last week, something broke the previously functional Postgresql schema syntax on my site(s). Up until the update, this was working fine: class Meta: db_schema = "world" db_table = "country" Once I performed the update, the following error occurs: File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 53, in __new__ new_class.add_to_class('_meta', Options(meta, **kwargs)) File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 213, in add_to_class value.contribute_to_class(cls, name) File "/usr/lib/pymodules/python2.6/django/db/models/options.py", line 93, in contribute_to_class raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())) TypeError: 'class Meta' got invalid attribute(s): db_schema I quickly reverted to the previous syntax to use class Meta: db_table='"world"."country"' which is working OK. It definitely resulted from the Debian upgrade, Unfortunately, I wasn't paying attention to the packages that were upgraded, and so I'm at a loss to pinpoint the error. The post-update packages are: python-django 1.2.1-1 postgresql 8.4.4-1 python 2.6.5+ Any ideas? Anything else I can supply to help diagnose this? -Steve -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: db_schema support was broken by Debian upgrade: 'class Meta' got invalid attribute(s): db_schema
On Sun, Jul 4, 2010 at 5:39 PM, MiddleForkGIS wrote: > During an update of Debian ("squeeze/sid") last week, something broke > the previously functional Postgresql schema syntax on my site(s). > > Up until the update, this was working fine: > > class Meta: > db_schema = "world" > db_table = "country" > > Once I performed the update, the following error occurs: > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > 53, in __new__ > new_class.add_to_class('_meta', Options(meta, **kwargs)) > File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line > 213, in add_to_class > value.contribute_to_class(cls, name) > File "/usr/lib/pymodules/python2.6/django/db/models/options.py", line > 93, in contribute_to_class > raise TypeError("'class Meta' got invalid attribute(s): %s" % > ','.join(meta_attrs.keys())) > TypeError: 'class Meta' got invalid attribute(s): db_schema > > I quickly reverted to the previous syntax to use > > class Meta: > db_table='"world"."country"' > > which is working OK. > > [...] > > Any ideas? Anything else I can supply to help diagnose this? > The meta.db_schema hast never been supported by Django. The version you were using most surely was one locally patched to add it. When the system was updated, you got a pristine Django 1.2.1 via the python django .deb package and that would explain what you are seeing. You can try to use the latest patch attached to ticket 6148 so you can help us with to test and enhance it. Warning: The patch, as every patch not merged in the official tree shouldn't be used on a production system, but the OS version and sysadmin practices you describe seems to indicate this isn't the case. Regards, -- Ramiro Morales | http://rmorales.net -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: *Immediate* session expiration problem/bug in IE
I have an update. It turns out that setting the timeout in set_expiry to a much larger value prevents the immediate timeout. Of course, this means that people in well-behaved browsers won't time out when they should. This is despite the fact that I've tried sending both an integer (for seconds) and a timedelta object to set_expiry, as described in the docs. My next step is to have a look at HTTP_USER_AGENT in request.META and see if I can find a correlation between its value and the timeout problem. Has anyone had experience with this, especially regarding whether HTTP_USER_AGENT is reliably present and accurate? Thanks, Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
manage.py ignores DJANGO_SETTINGS_MODULE
I have DJANGO_SETTINGS_MODULE set in my environment to an alternative settings file. The alternate file imports the original settings file and overrides some values for my development environment. Whenever I try to run ./manage.py runserver, it insists on using the settings.py on the same path as manage.py, despite the fact that running an interactive Python interpreter or a stand-alone script which imports settings from django.conf will import the proper settings file (from DJANGO_SETTINGS_MODULE). Also, this works: ./manage.py runserver --settings=$DJANGO_SETTINGS_MODULE I can see in manage.py that it assumes there's a settings.py in its own directory, but that's evidently overridden by the --settings flag. Why doesn't a correctly-set DJANGO_SETTINGS_MODULE result in the same behavior? I'm using Django 1.1.1. Thanks, Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
ModelAdmin with tabularinline Question
I am trying to write an application that credits a user's account when a bet is paid. I have an admin form with the bet and a TabularInline list of bet choices (the choices that can be bet on). To resolve a bet a ModelAdmin is used to set the status of the bet to True (paid) and the winner field on the winning bet choice to True. I am having troubles figuring out how to intercept saving from the admin to do the following: 1) get the old bet status 2) save the bet and bet choices 3) if the bet status changed from False to True, pay the bets (i.e. get booked bets whose bet field matches the bet id and whose choice winner field is True and notify the user they won). I tried overwriting the save function on the Bet model, but this is called before the bet choice changes are written to the database so I could not see who the winner is. Any idea how to solve the problem? It seems like I need to override some save function (the model? form? formset?) and get the status, call the super, then process the bets -- but I don't know which function to override and how to get to to the bet choice data from there. thanks, Len -- The models look this: class Bet(models.Model): choice = models.CharField(max_length=200) status = False # False: net not paid yet, True: Paid class BetChoice(models.Model): bet = models.ForeignKey(Bet) choice = models.CharField(max_length=200) winner = models.BooleanField(default=False) # True for winning choice class BookedBet(models.Model): bet = models.ForeignKey(Bet) choice = models.ForeignKey(BetChoice) user = models.ForeignKey(User) I also have a ModelAdmin set up as follows: class ChoiceInline(admin.TabularInline): model = BetChoice extra = 3 class BetAdmin(admin.ModelAdmin): fields = [ 'title','status'] inlines = [ChoiceInline] admin.site.register(Bet, BetAdmin) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: manage.py ignores DJANGO_SETTINGS_MODULE
If you read the source for django.core.management.__init__ you'll find a function called "setup_environ. This is called by all management commands (i.e. manage.py). If you note here the os.environ is set unconditionally. I suppose for your setup to work correctly django should be doing: if not "DJANGO_SETTINGS_MODULE" in os.environ: os.environ['DJANGO_SETTINGS_MODULE'] = ... However, since this is not the case you don't have much choice other then to use --settings option, or alter your manage.py file so that it sets up this hard-coded path before it calls the main setup_environ. Is the a particular reason to want an non-standard settings file? If the answer is yes, then carry on. Otherwise, I'd stick to what Django recommend. Euan On 5 July, 05:13, ShawnMilo wrote: > I have DJANGO_SETTINGS_MODULE set in my environment to an alternative > settings file. The alternate file imports the original settings file > and overrides some values for my development environment. > > Whenever I try to run ./manage.py runserver, it insists on using the > settings.py on the same path as manage.py, despite the fact that > running an interactive Python interpreter or a stand-alone script > which imports settings from django.conf will import the proper > settings file (from DJANGO_SETTINGS_MODULE). > > Also, this works: > ./manage.py runserver --settings=$DJANGO_SETTINGS_MODULE > > I can see in manage.py that it assumes there's a settings.py in its > own directory, but that's evidently overridden by the --settings flag. > Why doesn't a correctly-set DJANGO_SETTINGS_MODULE result in the same > behavior? I'm using Django 1.1.1. > > Thanks, > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: GROUP BY and ORDER BY using the ORM
Erm. You don't seem to have specified what to order by. In this case, surely you want ... .order_by('date_time') However, this field doesn't seem to appear in your models. One thing I've found handy for debugging Django's ORM to SQL is something which I don't think is documented in django docs at all (although I maybe wrong about that) is doing: print qs.query Where qs is your queryset. It will output the SQL Django sends to the DB backend. Euan On 3 July, 15:03, MikeHowarth wrote: > Hi all > > Just coming back to Django after a long time away, and struggling to > get my head around what should be a trivial concept using the ORM. > > Essentially I want to do acheive the following SQL: > > SELECT * FROM publisher_history > INNER JOIN publisher_publisher ON publisher_publisher.id = > publisher_history.publisher_id > GROUP BY publisher_id ORDER BY date_time DESC; > > My models look like this: > > class Publisher(models.Model): > name = models.CharField(max_length=100, blank=False) > > class History(models.Model): > publisher = models.ForeignKey(Publisher, blank=False) > > I've been trying to use object values, but I'm getting duplicate > publishers. Code looks like this: > > results = History.objects.values('publisher').distinct() > > If I run: > > results = History.objects.values('publisher').distinct().order_by() > > I don't get duplicates but I don't get the results returned in the > order I expect either. > > Any help would be greatly appreciated, I've stared at this for a while > now. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: New Django tutorial
Glad to be of assistance. Let me know when it's finished or if you want another look over, Euan On 3 July, 15:22, Rainy wrote: > Thanks for great feedback, Euan. I've added some comments below. > > On Jul 3, 8:26 am, "euan.godd...@googlemail.com" > > wrote: > > I had a look over your tutorial and it looks pretty sweet. Definitely > > gets down into explaining how to use the admin interface and taught me > > things I hadn't realized. I have a few suggestions for you (feel free > > to ignore :)): > > > 1) I'm not sure how good an idea it is to call the attribute on your > > DateTime model "datetime" - it conflicts with the datetime module. > > Although this shouldn't cause any problems, it might be confusing. > > Hm, maybe calling it 'created' is better.. but then you'll have > created.created which also doesn't look that great. I generally avoid > using names like list, tuple because they're built-ins and also > because they get highlighted in Vim :). Haven't really thought about > using module names.. In fact I don't think I ever ran into this > before. I'll have to think about this! > > > > > 2) In the "Changing Save Redirect" section you import a load of stuff > > inside an instance method. I'd prefer to see this imported at module > > level. > > I agree, that's what I do when I do actual development; but in this > case I made an exception to keep the tutorial shorter. Generally my > idea for this set of tutorials is to err on the side of maintaining > momentum rather than doing things by the book, I'll expand on this > idea more below. > > > 3) In the same section, you do request.POST.has_key. I believe the > > preferred syntax is "name_of_key" in request.POST. > > That's straight from Django sources :). > > > 4) In the same section you are using hard-coded URLs - can you not get > > these by using reverse() ? It might not be possible as I know the > > I want to introduce reverse() a bit later, in a larger tutorial where > it will be more self-evidently useful. So, the goal is to have someone > who's not a programmer go through the tutorial and feel that a useful > and practical app was done with very little code and only explain > enough concepts that are necessary for that particular app. Then, over > the course of the whole set of tutorials, various concepts will be > introduced at the exact point when they'd be most useful. > > On the other hand, I haven't actually used reverse() myself. I know > that it can get a little tricky. I'll definitely try to see if it > makes sense to introduce it in the view function. > > > admin is quite a beast. > > 5) In the mark_done method on Item, you could definitely use reverse > > and that should aid any changes to your URL structure. > > 6) In the "Customizing DateTime" your unicode method returns a str not > > unicode > > Good point - will fix that. > > > 7) In the same section you talk about an OnOff property. I think you > > actually mean attribute (although in terms of the concept it is indeed > > a property, just in terms of the model it is an attribute) > > Yes, that's where I have to balance use of language that sounds > clearer vs. fine points of terminology. I feel that most programming > tutorials are too quick to emphasize correct terminology, but I > definitely get where that comes from, too.. > > > 8) In the "Adding users" section, I think you could replace the loop > > with: > > > Item.objects.filter(created=obj, > > user_isnull=True).update(user=request.user). > > Good, this is actually new to me. I'll keep it in mind but I think for > the first tutorial the loop is clearer and this is something that > should be introduced when performance gain will be more apparent. > > > > > This would use only one SQL UPDATE and not n SELECTs and n UPDATEs. > > > 9) At the end when the possible actions are checked it might be nice > > to raise an exception if you don't find a valid action. > > Here, in fact, I'm following Django tutorial where they at one point > rely on the regex in urls.py and then explain that they're not > validating because it would not get through the regex if it were > wrong. On the other hand, depending on the project, I might raise an > exception if I feel that an error in the regex might be hard to debug > otherwise. > > > > > I hope you find the above helpful. There's very little wrong with the > > tutorial and it's really clear, but I think at least some of the > > points might be well incorporated. > > Very helpful - even if I didn't follow all of the advice, just > thinking and going through the reasons was extremely valuable. I > really appreciated the detailed critique, and I'd be very thankful if > you also looked at my future tutorials I'll also post here. -ak -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For mor
Re: manage.py ignores DJANGO_SETTINGS_MODULE
Also read: http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html where I explain a bit about startup steps. Graham On Jul 5, 4:25 pm, "euan.godd...@googlemail.com" wrote: > If you read the source for django.core.management.__init__ you'll find > a function called "setup_environ. This is called by all management > commands (i.e. manage.py). If you note here the os.environ is set > unconditionally. I suppose for your setup to work correctly django > should be doing: > > if not "DJANGO_SETTINGS_MODULE" in os.environ: > os.environ['DJANGO_SETTINGS_MODULE'] = ... > > However, since this is not the case you don't have much choice other > then to use --settings option, or alter your manage.py file so that it > sets up this hard-coded path before it calls the main setup_environ. > > Is the a particular reason to want an non-standard settings file? If > the answer is yes, then carry on. Otherwise, I'd stick to what Django > recommend. > > Euan > > On 5 July, 05:13, ShawnMilo wrote: > > > > > I have DJANGO_SETTINGS_MODULE set in my environment to an alternative > > settings file. The alternate file imports the original settings file > > and overrides some values for my development environment. > > > Whenever I try to run ./manage.py runserver, it insists on using the > > settings.py on the same path as manage.py, despite the fact that > > running an interactive Python interpreter or a stand-alone script > > which imports settings from django.conf will import the proper > > settings file (from DJANGO_SETTINGS_MODULE). > > > Also, this works: > > ./manage.py runserver --settings=$DJANGO_SETTINGS_MODULE > > > I can see in manage.py that it assumes there's a settings.py in its > > own directory, but that's evidently overridden by the --settings flag. > > Why doesn't a correctly-set DJANGO_SETTINGS_MODULE result in the same > > behavior? I'm using Django 1.1.1. > > > Thanks, > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.