Hi all, I have a custom model mapped to a view, a join between a UserContact model which carries contacts for users and UserContactEmail which is the emails for the contacts. Very simple join.
select concat(`t1`.`id`,'-',`t2`.`id`) AS `id`, `t2`.`usercontact_id` AS `usercontact_id`, `t1`.`user_id` AS `user_id`, `t1`.`first_name` AS `first_name`, `t1`.`last_name` AS `last_name`, `t1`.`is_locked` AS `is_locked`, `t1`.`manual_enter` AS `manual_enter`, `t1`.`is_trusted_contact` AS `is_trusted_contact`, `t1`.`is_admin` AS `is_admin`, `t2`.`email` AS `email` from (`auththis_usercontact` `t1` join `auththis_usercontactemail` `t2` on((`t1`.`id` = `t2`.`usercontact_id`)))$$ The Corresponding model is class View_UserContactEmail(models.Model): id = models.CharField(max_length=23, primary_key=True) usercontact_id = models.IntegerField() user_id = models.IntegerField() first_name = models.CharField('First name', max_length=30, blank=True) last_name = models.CharField('Last name', max_length=30, blank=True) is_locked = models.BooleanField("Locked", default=False) manual_enter = models.BooleanField("Hand Entered", default=False) is_trusted_contact = models.BooleanField("Trusted contact", default=False) is_admin = models.BooleanField("Admin", default=False) email = models.EmailField("Email", max_length=75,unique=True) class Meta: verbose_name = "User Contact Email" verbose_name_plural = "User Contact Emails" db_table = 'view_usercontactemail' def __unicode__(self): return "{0}: {1} {2} {3}".format(self.user, self.first_name, self.last_name, self.email) The django query: usercontactemails = View_UserContactEmail.objects.filter(user_id=user.pk ).filter(email='first_na...@firstname1.com') django result: first_na...@firstname1.com 1 firstname1 last_name1 first_na...@firstname1.com 3 first_name3 last_name3 the above columns are email, first name, last name Mysql: Turns back 1 row as it should but django turns back 2 rows 1 with false data mysql> select * from view_usercontactemail where email=' first_na...@firstname2.com' and user_id=1; +-----+----------------+---------+-------------+------------+-----------+--------------+--------------------+----------+----------------------------+ | id | usercontact_id | user_id | first_name | last_name | is_locked | manual_enter | is_trusted_contact | is_admin | email | +-----+----------------+---------+-------------+------------+-----------+--------------+--------------------+----------+----------------------------+ | 2-3 | 2 | 1 | first_name2 | last_name2 | 0 | 1 | 1 | 0 | first_na...@firstname2.com | +-----+----------------+---------+-------------+------------+-----------+--------------+--------------------+----------+----------------------------+ Mysql is correct so maybe I am wrong, can someone please take a look and see if they see something. PS the weird id column in the view is to accommodate django's need for a primary key thanks --jerry Arch Awesome, Ranger & Vim the coding triple threat. Linux registered user #548580 -- 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.