Re: class with a ForeignKey and ManyToManyField, empty sql IN () clause after admin save

2006-10-04 Thread L. Liddell

Thanks Russell.

Although the patch for that ticket did not work in my particular case,
I was able to modify the patch slightly to solve my problem. For anyone
else with the same problem, here's my patch for
django/db/models/query.py:

643 if lookup_type == 'in':
644 #return '%s%s IN (%s)' % (table_prefix, field_name,
','.join(['%s' for v in valu
645 ### MY CODE
646 ids = list(value)
647 if ids:
648 return '%s%s IN (%s)' % (table_prefix, field_name,
','.join(['%s' for id in
649 else:
650 return '%s%s IN (0)' % (table_prefix, field_name)
651 ### END OF MY CODE

I don't think this should cause problems anywhere else, but use at your
own risk! Hopefully by mid November when my site launches, the most
recent revision of Django will have solved this issue and there will be
no need for patched Django source code.

cheers,
Les Liddell


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



class with a ForeignKey and ManyToManyField, empty sql IN () clause after admin save

2006-10-03 Thread L. Liddell

Here's a simplified version of what I need to accomplish:

  1 from django.db import models
  2
  3 class Category(models.Model):
  4 name = models.CharField(maxlength=255)
  5 def __str__(self):
  6 return self.name
  7 class Admin: pass
  8
  9 class Listing(models.Model):
 10 name = models.CharField(maxlength=255)
 11 def __str__(self):
 12 return self.name
 13 class Admin: pass
 14
 15 class Location(models.Model):
 16 name = models.CharField(maxlength=255,core=True)
 17 listing = models.ForeignKey(Listing,
edit_inline=models.STACKED, num_in_admin=1)
 18 categories = models.ManyToManyField(Category, blank=True,
null=True)
 19 def __str__(self):
 20 return self.name
 21 class Meta:
 22 ordering = ['listing','id']

Now I have no problem using this model at all from the command line.
However, when I try to save a Listing and Location (the inline FK) with
the categories (M2MField) left BLANK, I get an empty SQL IN () clause
in my error on the POST:

Exception Value:ERROR: syntax error at or near ")" at character 113
SELECT "vendor_category"."id","vendor_category"."name" FROM
"vendor_category" WHERE ("vendor_category"."id" IN ())

The data is saved fine and I can refresh the page with a GET that
returns proper page. If a value is selected for the categories
(M2MField), then this does not occur.

I had this working in a previous revision of Django 0.95, but it broke
when I updated the revision I'm using.

Any ideas?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---