Re: Django Troubleshooting
you should use pip to install, why are you installing from source? if you are worried about filling your python installation with lots of stuff you should use virtualenv On Fri, Oct 19, 2012 at 6:15 AM, Lachlan Musicman wrote: > On Fri, Oct 19, 2012 at 4:07 PM, Sun Simon wrote: > > https://www.djangoproject.com/download/ > > > > I am installing Django for Python on Win XP and came across this problem > > during installation: > > > > > > tar xzvf Django-1.4.2.tar.gz > > cd Django-1.4.2 > > sudo python setup.py install > > > > > > What does "cd" mean? DOes it mean that I have to use command line to type > > it? > > Yes, those are linux commands - you need to be in the directory. > > I've not installed on Windows, but sudo wont work either, FYI. Run the > cmd as administrator and you wouldn't need it > > Cheers > L. > > > > > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To view this discussion on the web visit > > https://groups.google.com/d/msg/django-users/-/RmTilhDq4WIJ. > > 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. > > > > -- > ...we look at the present day through a rear-view mirror. This is > something Marshall McLuhan said back in the Sixties, when the world > was in the grip of authentic-seeming future narratives. He said, “We > look at the present through a rear-view mirror. We march backwards > into the future.” > > http://www.warrenellis.com/?p=14314 > > -- > 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: ordering by generic foreign key
I tried that: favorites = Photo.objects.filter(likes__user=user).order_by("-likes__id") and it seems to work well in all the tests. The only thing I don't understand is how it works. Because in this generic relation there are various 'likes' for each 'Photo' object and so the 'filter(likes__user=user)' part must iterate through them in a way. Anyway it works. Cheers, Bastian On Thursday, October 18, 2012 6:46:14 PM UTC+2, Bastian wrote: > > Hi, I'm not sure to understand what I'm doing here :) I have a model of a > photo with name, description, image field... and a generic foreign key > called 'likes' to store the photo in users' favorites: > likes = generic.GenericRelation(Like) > > and in the Like model I have: > user = models.ForeignKey(User) > > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > > Now when I want to display a user's favorites I can do: > q = Q(likes__user=user) > favorites = Photo.objects.filter(q) > > > it works ok but the result is ordered by Photo pk so if a user likes a > photo that has been uploaded a long time ago it appears very far away in > the favorites list. I would like to order that list by the pk of the Like > object but I have no idea how to do that. > I don't know if I made myself clear. Any help is welcome. > Cheers, > Bastian > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xTMPktiyMGQJ. 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.
Stop executing template tag
Hello people I need some suggestion in a problem. How can i stop django template engine not executing {{name}}. Meaning I do not want that {{}}, the value should be printed it should somehow pass into the browser as it is. If i writing {{name}} it should print {{name}} in html file/browser How can i achieve this ? -- Regards Nikhil Verma +91-958-273-3156 -- 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: Stop executing template tag
Just put something between the {{ so the templating engine will not be tempted to interpret it. {{ should do the trick, for example. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/MONhRYIc46YJ. 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: Stop executing template tag
Hi Nikhil, you can't do that with django template system without additional "raw" tag. Here's a relevant article: http://www.holovaty.com/writing/django-two-phased-rendering/ Cheers, Tom Dne Fri, 19 Oct 2012 15:51:39 +0530 Nikhil Verma napsal(a): > Hello people > > I need some suggestion in a problem. > > How can i stop django template engine not executing {{name}}. Meaning I do > not want that {{}}, the value should be printed it should somehow pass into > the browser as it is. > If i writing {{name}} it should print {{name}} in html file/browser > > How can i achieve 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: Stop executing template tag
On Fri, Oct 19, 2012 at 11:40 AM, Tomas Ehrlich wrote: > Hi Nikhil, > you can't do that with django template system without additional "raw" tag. > > Here's a relevant article: > http://www.holovaty.com/writing/django-two-phased-rendering/ > > Cheers, > Tom Oh really? {% templatetag openvariable %} name {% templatetag closevariable %} Cheers Tom -- 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: Stop executing template tag
On Fri, Oct 19, 2012 at 6:21 PM, Nikhil Verma wrote: > Hello people > > I need some suggestion in a problem. > > How can i stop django template engine not executing {{name}}. Meaning I do > not want that {{}}, the value should be printed it should somehow pass into > the browser as it is. > If i writing {{name}} it should print {{name}} in html file/browser You have two options: Option 1 - Use the {% templatetag %} templatetag: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag {% templatetag openvariable %} hello {% templatetag closevariable will render as {{ hello }} Option 2 -- if you have a large block of text that you want to render, you can use the {% verbatim %} template tag {% verbatim %} This {{ content }} won't be processed. {% endverbatim %} Unfortunately, this option is only available in Django's trunk (so it will be part of Django 1.5). However, there are plenty of snippets of code you can use (including copying Django's own implementation) that you can use in your own project. Yours, Russ Magee %-) -- 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: "Error: unable to open database file" when trying out the Django tutorial
I am getting the exact same error . did you find out what was wrong ? On Friday, 25 March 2011 21:51:24 UTC+11, kpk wrote: > > I was trying out the tutorial "Writing your first Django app, part 1" > at http://docs.djangoproject.com/en/1.3/intro/tutorial01/. > > The configuration is as follows: Windows XP SP2, Python 2.5.2, > Django 1.3. > > The tutorial succeeded up to the stage of creating a project and > demonstration the "Welcome to Django" page. > But when it came to database setup I am having the following problem. > > I have modified the settings.py file with the following entries: > > 'ENGINE': 'django.db.backends.sqlite3', > 'NAME': 'E:/Users/python/mysite/ > mysite.db', > > Now when I run > python manage.py syncdb > I get an error DatabaseError: unable to open database file > But the file mysite.db is created in the folder. > The file and folder has write permission for all users. > The full output of the command is as follows: > > > E:\Users\python\mysite>python manage.py syncdb > Traceback (most recent call last): > File "manage.py", line 14, in > execute_manager(settings) > File "D:\Program Files\Python25\Lib\site-packages\django\core > \management\__ini > t__.py", line 438, in execute_manager > utility.execute() > File "D:\Program Files\Python25\Lib\site-packages\django\core > \management\__ini > t__.py", line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "D:\Program Files\Python25\Lib\site-packages\django\core > \management\base. > py", line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File "D:\Program Files\Python25\Lib\site-packages\django\core > \management\base. > py", line 220, in execute > output = self.handle(*args, **options) > File "D:\Program Files\Python25\Lib\site-packages\django\core > \management\base. > py", line 351, in handle > return self.handle_noargs(**options) > File "D:\Program Files\Python25\Lib\site-packages\django\core > \management\comma > nds\syncdb.py", line 59, in handle_noargs > tables = connection.introspection.table_names() > File "D:\Program Files\Python25\Lib\site-packages\django\db\backends > \__init__. > py", line 792, in table_names > return self.get_table_list(cursor) > File "D:\Program Files\Python25\Lib\site-packages\django\db\backends > \sqlite3\i > ntrospection.py", line 51, in get_table_list > ORDER BY name""") > File "D:\Program Files\Python25\Lib\site-packages\django\db\backends > \util.py", > line 34, in execute > return self.cursor.execute(sql, params) > File "D:\Program Files\Python25\Lib\site-packages\django\db\backends > \sqlite3\b > ase.py", line 234, in execute > return Database.Cursor.execute(self, query, params) > django.db.utils.DatabaseError: unable to open database file > > > Can you pls help? Thanks in advance. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Gip5B3e_fhgJ. 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.
File Storage help
Hi all, I want to know who has an example for file sharing service written in Django... Recently I have to write a file sharing project for students sharing their files in order to improve the usability and experience... So can anyone help me? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/TWs_0yLc_wUJ. 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: __unicode__() addition not working in basic poll application.
Restart your interactive shell by *exit() *first then *python manage.py shell*. It's works for me -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/AYBiKDc7a-gJ. 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: Better feedback for admin users
On Thu, Oct 18, 2012, Marc Aymerich wrote: >On Wed, Oct 17, 2012 at 12:21 AM, Daniele Procida wrote: >> I am starting to customise the admin classes for my models so that I >can provide extra feedback to the user. >> >> For example I want to report - in the admin page - useful information >about how the system will interpret the current state of the object >being edited. >> >> I'm doing this by using readonly_fields, that contain the output of >method on the ModelAdmin class, a bit like this: >> >> class PersonAdmin(ModelAdmin): >> readonly_fields = ['check_address',] >> >> def check_address(self, instance): >> return instance.get_full_address or "class='errors'>Warning: I am unable to work out an address for this >person." >> >> (the actual examples are rather more complex, but this is the idea). >> >> Does a more elegant way of doing this exist, either in Django's core >already, or using some package that makes it easier? >> > >don't know for a best way, but for me the one you're describing its >actually a good workaround that maybe I'll use :) >thanks for sharing ! You're welcome! Note that you can also use methods of the Model as readonly_fields, but you can't use properties (because you can't assign attributes to the properties that you might need, like: check_address.short_description = "Address" # a bit like verbose_name check_address.allow_tags = True # so you can use HTML in the output ). It would maybe be nicer to be able to use properties, for me anyway, since really these are attributes of the model class, and might also want to use elsewhere. Daniele -- 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.
Calculated attributes of ModelAdmin classes
I have a ModelAdmin class. Sometimes, I want it to include a certain field in the fieldsets, and sometimes I don't (whether it does or not would be the result of a calculation on the instance that is being edited in the admin). How can I make the fieldsets attribute a calculated value, calculated each time a different instance is loaded in the admin? Another example: I might want a certain field to be a readonly_field - sometimes. Is this possible? I have a feeling it won't be, because: * attributes like fieldsets and readonly_fields are set up in the __init__() * once set up, they don't seem modifiable * the __init__() doesn't have access to the instance, so use that to determine the attributes Daniele -- 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: Adding values in my database via a ManyToMany relationship represented in admin.py
i'm not clear about your models: - the admin inline refers to a RunHasSample model that i don't see in your models.py - the Sample model has an FK to Sample, but looks like the run_has_sample table. Should i presume that's the RunHasSample intermediary model instead? - i don't see your tables for Run or Sample, which may not be relevant, but given my present confusion, might help - It seems like RunHasSample is an explicit intermediary between Run and Sample, and then there is also an intermediary table between RunHasSample and Line. That means your explicit m2m intermediary table has an implicit m2m to et another table. Is that what you want? i'm lost at that point. Did you look over the m2m admin inlines section in the docs? https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#working-with-many-to-many-models The usage of `model = Group.members.through` might be a hint, and then there's additional info on working with intermediary models as well. On Friday, October 19, 2012 4:09:10 AM UTC-5, Louise OTT wrote: > > Hello all ! > > I posted my problem on stackoverflow but I didn't get any answer. I think > this is something really simple. I just need to fullfill my database via a > ManyToMany field... Why doesn't it work ? I don't know, but I am > desperate... > > I give you the link : > http://stackoverflow.com/questions/12918651/adding-values-in-my-database-via-a-manytomany-relationship-represented-in-admin > > It would be fan-ta-stic if you would know the answer... > > Here is the copy/paste : > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/MyQ3z4RHoV8J. 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: loop user.get_profile displays none in a template
i think you'd have to make a method on UserProfile that returns a dict of some of its attributes, and iterate over the result of that method in your template. That, or create a templatetag that adds it to the context. On Thursday, October 18, 2012 10:52:39 PM UTC-5, David Lee wrote: > > how can I get each key and value by loop or another method? I wanna > display all infomations about a model instance > > 在 2012年10月19日星期五UTC+8上午11时33分48秒,Matt Schinckel写道: >> >> user.get_profile() returns a model instance, not a dict. Model instances >> have no .items() method. >> >> Matt. >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/AWXiJGnTZzUJ. 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: Adding values in my database via a ManyToMany relationship represented in admin.py
> > In [10]: run1= Run(project=Project.objects.get(pk=1), >> sequencing_type=SequencingType.objects.get(pk=1)) > > >> In [11]: run1.save() > > >> In [12]: Run.objects.all() > > Out[12]: [] > > >> In [13]: s1=RunHasSample(run=run1, sample=Sample.objects.get(pk=1), >> dna_quantification_ng_per_ul=1) > > >> In [14]: s1.save() > > >> In [15]: run1.lines.add(s1) > > --- > > AttributeErrorTraceback (most recent call last) > > /opt/scyld/python/2.6.5/lib/python2.6/site-packages/django/core/management/commands/shell.pyc > >> in () > > > 1 run1.lines.add(s1) > > >> AttributeError: 'Run' object has no attribute 'lines' > > >> In [16]: run1.lines.add(s1) > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/I6TXmhL9rCwJ. 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: Adding values in my database via a ManyToMany relationship represented in admin.py
It's true: the Run model does not have a "lines" attribute; the RunHasSample model does. Also, `s1` is not a Line nor a Sample, it's an instance of the intermediary RunHasSample. So you're not going to be able to directly add a Line instance to a Run instance- you'll have to add it to the relevant RunHasSample instance instead. On Friday, October 19, 2012 11:11:57 AM UTC-5, Louise OTT wrote: > > In [10]: run1= Run(project=Project.objects.get(pk=1), >>> sequencing_type=SequencingType.objects.get(pk=1)) >> >> >>> In [11]: run1.save() >> >> >>> In [12]: Run.objects.all() >> >> Out[12]: [] >> >> >>> In [13]: s1=RunHasSample(run=run1, sample=Sample.objects.get(pk=1), >>> dna_quantification_ng_per_ul=1) >> >> >>> In [14]: s1.save() >> >> >>> In [15]: run1.lines.add(s1) >> >> >>> --- >> >> AttributeErrorTraceback (most recent call >>> last) >> >> /opt/scyld/python/2.6.5/lib/python2.6/site-packages/django/core/management/commands/shell.pyc >> >>> in () >> >> > 1 run1.lines.add(s1) >> >> >>> AttributeError: 'Run' object has no attribute 'lines' >> >> >>> In [16]: run1.lines.add(s1) >> >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/2oK9vg_3HfUJ. 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: Unhandled exception during validation
Sorry for the late reply ! Yes, you are correct. My point is, that something crashed somewhere, and there is no stack trace or anything that indicates what the problem is. -- Oyvind On Friday, October 12, 2012 6:00:22 PM UTC+2, Tom Evans wrote: > > On Fri, Oct 12, 2012 at 4:45 PM, Tomáš Ehrlich > > > wrote: > > Hello Oyvind, > > that's weird, Django (or Python in general) usually provide very long > and > > descriptive trackback. > > > > Could you please provide more information? What version of Python do you > > have? Does it fail when you run ./manage.py runserver? You've mentioned, > the > > error is in local app, does that app load any thirdparty modules? > > > > I've never came across unhandled exception which doesn't show trackback, > so > > my guess is some c/c++ python extension (PIL, psycopg2, …). But that's > just > > guess… > > > > Cheers, > > Tom > > I think you've misunderstood the OP, the error occurs in Django's > AppCache, which is populated when you start django in any manner (even > going to the shell). The error occurs when AppCache tries to load one > of his custom apps, and the issue is that the error message does not > indicate the error that occurred, provide a proper traceback or even > indicate which app it failed to load. > > (Sorry OP, haven't a clue) > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/87wbyhQSQPUJ. 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: Custom User class -> createsuperuser asks for Username twice
Right on. Thanks Russ. On Thursday, October 18, 2012 3:38:05 PM UTC-4, Chris Pagnutti wrote: > > Hi. I'm just trying out the new way to create a custom User class by > extending the AbstractBaseUser class. I essentially just copied the > AbstractUser and UserManager classes from auth.models and customized the > fields the way I want 'em. I also set AUTH_USER_MODEL in settings > appropriately. > > But when I do syncdb, the tables get created fine, but when I try to > create a superuser, it asks for the username twice, then throws this error > > TypeError: create_superuser() got multiple values for keyword argument > 'username' > > Anyone know what's going on? > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/yTsntMhIRmcJ. 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.
Postgresql Index & expensive queries [n00bie alert]
I've got a pretty expensive query...Wondering if I can't speed things up in regards to Postgresql. Here is the model: [1] http://dpaste.org/JmEeQ/ Here is the sql statement: [2] http://dpaste.org/GbfAJ/ Here is the template: [3] http://dpaste.org/vxRs4/ Here is the 'guts' of the view: [4] http://dpaste.org/w0b2z/ Total Postgresql/SQL n00b, so this may be a stupid statement. I'm wondering if an index on '"press_page"."article_id"' wouldn't speed things up a bit? In dev, I don't have the amount of data that exists in production, so I can't easily/realistically recreate this scenario. FWIW, I'm running: - Django 12.04 - Postgresql 9.1.5 - Django 1.4.1 I'm using memcache on the view to cache it, it helped take page load down significantly, but I was wondering if there wasn't something I could do from the DB side of things since I know it's this query that is taking the page so long to load. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/U92OjnMgEggJ. 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: Postgresql Index & expensive queries [n00bie alert]
On 20 October 2012 14:16, Barry Morrison wrote: > I've got a pretty expensive query...Wondering if I can't speed things up in > regards to Postgresql. > > Here is the model: [1] http://dpaste.org/JmEeQ/ > > Here is the sql statement: [2] http://dpaste.org/GbfAJ/ > > Here is the template: [3] http://dpaste.org/vxRs4/ > > Here is the 'guts' of the view: [4] http://dpaste.org/w0b2z/ > > Total Postgresql/SQL n00b, so this may be a stupid statement. I'm wondering > if an index on '"press_page"."article_id"' wouldn't speed things up a bit? Are you using the django-debug-toolbar? If not, consider using it - once installed, visit that page in your browser, open up the toolbar, select SQL queries, find the offending query (processing times are shown), and click the Explain link. That will tell you what PostgreSQL is doing, and how performance can be improved. Alternately, fire up a terminal and launch the psql database shell. Type in the query ([2]) but prefix it with the word EXPLAIN. This will tell you what PostgreSQL is doing to process that query. If you see Seq Scan in there, consider adding the index. Remember to run the SQL statement - ANALYZE press_page - after you create the index so it can update the internal statistics that it uses to decide how to process a query. You can also do this within the PGadmin application if that makes things easier. > In dev, I don't have the amount of data that exists in production, so I > can't easily/realistically recreate this scenario. You really need to have a good subset (considering both the number of records, and the distribution of values within each record) if it is not possible to have a copy of the production database. PostgreSQL performs analysis on the data itself and uses those statistics to decide how to process the query (whether to use an index, scan sequentially etc.). If you dev database is not a good representation, then the results you'll see with your dev database, and hence your improvements, may have no effect or a negative effect in production. I do believe having an index on press_page.article_id is a good idea though. Also, are you really showing every article in that view? Consider using a limit so you're not retrieving all the records, only to use the first 10. The pagination features in Django may be useful here. Finally, an index on press_page.pgnumber may also be worth considering so PostgreSQL may be able to avoid the sorting step (an index of the default type is sorted by the field in ascending order). > FWIW, I'm running: > > Django 12.04 > Postgresql 9.1.5 > Django 1.4.1 > > I'm using memcache on the view to cache it, it helped take page load down > significantly, but I was wondering if there wasn't something I could do from > the DB side of things since I know it's this query that is taking the page > so long to load. > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/U92OjnMgEggJ. > 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: Postgresql Index & expensive queries [n00bie alert]
Hi, As Samuel said, the first step is to install Django Debug Toolbar to see what's going on with your queries. Then you'll probably be interested in https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related Regards, Xavier Ordoquy, Linovia. Le 20 oct. 2012 à 05:16, Barry Morrison a écrit : > I've got a pretty expensive query...Wondering if I can't speed things up in > regards to Postgresql. > > Here is the model: [1] http://dpaste.org/JmEeQ/ > > Here is the sql statement: [2] http://dpaste.org/GbfAJ/ > > Here is the template: [3] http://dpaste.org/vxRs4/ > > Here is the 'guts' of the view: [4] http://dpaste.org/w0b2z/ > > Total Postgresql/SQL n00b, so this may be a stupid statement. I'm wondering > if an index on '"press_page"."article_id"' wouldn't speed things up a bit? > > In dev, I don't have the amount of data that exists in production, so I can't > easily/realistically recreate this scenario. > > FWIW, I'm running: > > Django 12.04 > Postgresql 9.1.5 > Django 1.4.1 > I'm using memcache on the view to cache it, it helped take page load down > significantly, but I was wondering if there wasn't something I could do from > the DB side of things since I know it's this query that is taking the page so > long to load. > > Thanks! > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/U92OjnMgEggJ. > 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.