Re: Preventing JOIN while checking if a self referencing FK is null
Is there a reason why editor_id is meant to raise a field error? -Daniel On Mar 21, 12:05 pm, diafygi <diaf...@gmail.com> wrote: > >>> Blog.objects.filter(editor_id=None) > > FieldError: Cannot resolve keyword 'editor_id' into field. > > This was actually an offered answer in the previous thread, but the id > version of the field still raises a field error. > > Daniel > > On Mar 21, 9:47 am, Javier Guerra Giraldez <jav...@guerrag.com> wrote: > > > > > > > > > try: > > > > Blog.objects.filter(editor_id=None) > > > -- > > Javier -- 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: Preventing JOIN while checking if a self referencing FK is null
I cannot confirm that behavior. Can others verify? I'm using Django 1.3 and I get: >>> print Blog.objects.filter(editor=None).values('id').query SELECT `myapp_blog`.`id` FROM `myapp_blog` LEFT OUTER JOIN `myapp_user` ON (`myapp_blog`.`editor_id` = `myapp_user`.`id`) WHERE `myapp_user`.`id` IS NULL -Daniel On Mar 21, 2:07 pm, Andre Terra <andrete...@gmail.com> wrote: > On Wed, Mar 21, 2012 at 5:41 AM, diafygi <diaf...@gmail.com> wrote: > > >>> Blog.objects.filter(editor=None) > > >>> print Blog.objects.filter(editor=None).values('id').query > > SELECT "myapp_blog"."id" FROM "myapp_blog" WHERE "myappblog"."editor_id" IS > NULL > > Cheers, > AT -- 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: Preventing JOIN while checking if a self referencing FK is null
>>> Blog.objects.filter(editor_id=None) FieldError: Cannot resolve keyword 'editor_id' into field. This was actually an offered answer in the previous thread, but the id version of the field still raises a field error. Daniel On Mar 21, 9:47 am, Javier Guerra Giraldezwrote: > try: > > > Blog.objects.filter(editor_id=None) > > -- > Javier -- 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.
[bump] Preventing JOIN while checking if a self referencing FK is null
There is an old thread that didn't end in a resolution about preventing joins in a filter(foreign_key=None) scenario. http://groups.google.com/group/django-users/browse_thread/thread/61ee2fb22deae326 I'd like to bring it up again and ask if there is now a way to prevent joins from a query. An example: class Blog(model.Models): editor = models.ForeignKey(User, null=True) # find all the blogs with no editors >>> Blog.objects.filter(editor=None) DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM `myapp_blog` LEFT OUTER JOIN `myapp_user` ON (`myapp_blog`.`editor_id` = `myapp_user`.`id`) WHERE `myapp_user`.`id` IS NULL; # Is there a way to do this query? >>> Blog.objects.filter(editor=None) DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM `myapp_blog` WHERE `myapp_blog`.`editor_id` IS NULL; Thanks! Daniel -- 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-open] viewing generated SQL without running the query
There's a previous thread about this[1], but it was closed back in 2006 without resolution. So I'd like to check back in and see if there is a way to get a complete query string without executing the query. At first, I thought I could just use the QuerySet.query.__str__(), but that does not put quotes around dates, so MySQL returns a warning when trying to execute it. I filed a bug report[2], but apparently QuerySet.query.__str__() isn't supposed to return a valid query string. So is there a way to get the compiled query string without executing the query (including when debug=False)? Thanks! Daniel [1] - http://groups.google.com/group/django-users/browse_thread/thread/37a6222006d0633b/ [2] - https://code.djangoproject.com/ticket/17741 -- 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.
Way to identify affected rows from a delete in the admin
In the django admin site, it lists the entries that will be deleted via cascade if you want to delete something. I'm wondering if you can do something similar in the shell to identify the rows affected by a deletion. Is there such a function in django to show the list of casade deletes like in the admin? If not, what can I do to create that list? This would be very helpful if you accidentally deleted an entry that affected many rows (i.e. an auth User or something), so that you could identify the affected rows from a backup, then re-insert them into the database. Thanks, Daniel -- 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: Format queryset return dictionary of primary keys?
Right, that's what I'm currently doing. I was just wondering if there was a pre-defined way. On Aug 4, 4:06 pm, Shawn Milochikwrote: > I don't know about built-in, but you could do it in Python by iterating > through your list and creating a dictionary with a key of the id and > value of the rest of the dictionary. -- 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.
Format queryset return dictionary of primary keys?
Howdy all, I'm know you can create a list of dictionaries for a queryset using values(). However, I'm wondering if you can create one dictionary where the keys are the primary keys of the result. For example: class Car(models.Model): vin = models.IntegerField() >>Model.objects.all().values() [{'id' : 1, 'vin' : 189554}, {'id' : 1, 'vin' : 189555}, ...] Is there a built in way to get: >>Model.objects.all().something_pk_values() {1 : {'vin':189554}, 2 : {'vin':189555}} Thanks! Daniel -- 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.
Disable debug logging for django.db.backends?
Howdy all, I have DEBUG=True in my settings.py, and I have several logging entries in my project (Django 1.3) However, when I am testing, there are tons of django.db.backends debug entries that appear, and my logs gets lost in the shuffle. Is there a way to disable django.db.backends in my settings.py? What is an example? Thanks, Daniel -- 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.