Note that there are some explanatory texts on larger screens.

plurals
  1. PODJANGO: many-to-many relationship with additional fields
    primarykey
    data
    text
    <p>New to programming and this is very confusing for me... I have 2 models. Department and Crossfunctionalproject. The relationship between the two models creates a join table called Department_Crossfunctionalproject. </p> <p>I have another model called employee. I want to add employees to the Department_Crossfunctionalproject table. How can I do this? </p> <p>I've been following this tutorial: <a href="https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships</a>. Can I not do this on the automatically created department_crossfunctionalproject join table that DJANGO creates? </p> <p>I keep getting the following error:</p> <pre><code>CommandError("One or more models did not validate:\n%s" % error_text) django.core.management.base.CommandError: One or more models did not validate: companydatabase.membership:"Department_crossfunctionalproject" has a relationship with model &lt;class 'companydatabase.models.Department_crossfunctionalproject'&gt;, which has either not been installed or is abstract. </code></pre> <p>MODELS:</p> <pre><code>class Crossfunctionalproject(models.Model): nameofproject = models.CharField(max_length=50) def __unicode__(self): return self.nameofproject class Department(models.Model): name = models.CharField(max_length=100) project = models.ManyToManyField(Crossfunctionalproject, null=True, blank=True) class Employee(models.Model): employeenumber = models.CharField(max_length=50) fname = models.CharField(max_length=50, verbose_name='First Name') mname = models.CharField(max_length=50, null=True, blank=True, verbose_name='Middle Name') lname = models.CharField(max_length=50, verbose_name='Last Name') email = models.EmailField(null=True, blank=True, verbose_name='Email') phone = models.CharField(max_length=50, null=True, blank=True, verbose_name='Phone') title = models.CharField(max_length=50, null=True, blank=True, verbose_name='Position') # db table created by DJANGO, I wrote out the model, trying to add extra columns* class Department_crossfunctionalproject(models.Model): department = models.ForeignKey(Department) crossfunctionalproject = models.ForeignKey(Crossfunctonalproject) membership = models.ManyToManyField(Employee, through="Membership") class Membership(models.Model): employee = models.ForeignKey(Employee) department_crossfunctionalproject = models.ForeignKey(Department_crossfunctionalproject) whytheyjoined = models.CharField(max_length=100) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload