Thanks a lot! That worked. On Tue, Jul 19, 2011 at 9:22 PM, Nan <ringe...@gmail.com> wrote: > > Try unique_together on employee and team in the TeamMember model -- it > will throw an error if you try to add a record with the same employee > and team as another. > > On Jul 19, 7:27 pm, Felipe Spychalski <spychal...@gmail.com> wrote: >> Hello, >> >> I'm having an issue with my schema and the admin interface where I got >> 2 tables with a ManyToMany relationship: Employee and Team. >> The problem is I'm able to add one Employee to the same Team twice. >> Is there a way to prevent this from happening? Adding 'unique' to the >> Employee FK makes it so Employees can only join one Team). >> >> The code I'm using (irrelevant parts removed): >> >> from django.db import models >> from django.contrib.auth.models import User >> >> class Employee(models.Model): >> name = models.CharField(max_length=30, unique=True) >> user = models.ForeignKey(User) >> >> class Team(models.Model): >> name = models.CharField(max_length=60) >> members = models.ManyToManyField('Employee', blank=True, >> through='TeamMember') >> >> class TeamMember(models.Model): >> employee = models.ForeignKey(Employee) >> team = models.ForeignKey(Team) >> is_leader = models.BooleanField('Is Leader?') >> >> Thanks in advance. > > -- > 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.