﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7042	Admin Interface generates malformed SQL with many-to-many fields	alexander.hungenberg@…	Charlie La Mothe	"I am using latest Revision (7438)[[BR]]
[[BR]]

{{{
class Teacher(models.Model):
    short = models.CharField(max_length=20)
    account = models.ForeignKey(User, unique=True, blank=True, null=True)
    
    def __unicode__(self):
        if self.account:
            return self.account.last_name + "", "" + self.account.first_name
        else:
            return self.short
    
    class Admin:
        list_display = ('account', 'short')

class Class(models.Model):
    name = models.CharField(max_length=3, unique=True)
    teacher = models.ManyToManyField(Teacher, unique=True, blank=True, null=True)
    room = models.ForeignKey(Room, blank=True, null=True)
    enabled_functions = models.ManyToManyField(Function, blank=True, null=True)
    
    def __unicode__(self):
        return self.name
    
    class Admin:
        list_display = ('name', 'room')
}}}


When I try to add a Teacher to a Class via the admin-interface, it throws the following Exception:[[BR]]

(1064, ""You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1"")

the executed query taken from MySQL Log is[[BR]]

SELECT `m2db_class`.`id`,`m2db_class`.`name`,`m2db_class`.`room_id` FROM `m2db_class` LEFT OUTER JOIN `m2db_class_teacher` AS `m2m_m2db_class__teacher` ON `m2db_class`.`id` = `m2m_m2db_class__teacher`.`class_id` WHERE (`m2m_m2db_class__teacher`.`teacher_id` = (""'1'"",))[[BR]]
[[BR]]
Other many-to-many fields work normal...[[BR]]
[[BR]]


If you need further Infos, contect me by mail or as defreng in #django. I could even give you some access to the admin page

"		closed	Database layer (models, ORM)	dev		fixed	aug22sprint	charlie@…	Accepted	1	0	0	0	0	0
