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.
I have another model called employee. I want to add employees to the Department_Crossfunctionalproject table. How can I do this?
I've been following this tutorial: https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships. Can I not do this on the automatically created department_crossfunctionalproject join table that DJANGO creates?
I keep getting the following error:
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 <class 'companydatabase.models.Department_crossfunctionalproject'>,
which has either not been installed or is abstract.
MODELS:
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)