I have the following models
app1.models.py
class UserProfile(Subject):
"""
UserProfile class
"""
# This field is required.
user = models.OneToOneField(User)
# Other fields here
company = models.CharField(max_length=50, null=True, blank=True,
verbose_name=("Company"))
contact = models.CharField(max_length=50, null=True, blank=True,
verbose_name=("Contact"))
msg = models.TextField(null=True, blank=True, verbose_name=_("Message"))
def __unicode__(self):
return self.user.username
class ParentImportJob(models.Model):
"""
Class to store importing jobs
"""
STATUS_ACTIVE = u'A'
STATUS_SUCCESS = u'S'
STATUS_PARTIAL = u'P'
STATUS_ERROR = u'E'
STATUS_CHOICES = (
(STATUS_ACTIVE, _(u'In Progress')),
(STATUS_SUCCESS, _(u'Successfully Imported')),
(STATUS_PARTIAL, _(u'Partially Imported')),
(STATUS_ERROR, _(u'Aborted with error')),
)
status = models.CharField(max_length=1, choices=STATUS_CHOICES)
user_profile = models.ForeignKey(UserProfile)
errors = models.TextField(null=True, blank=True)
start_date = models.DateTimeField(auto_now_add=True)
end_date = models.DateTimeField(blank=True, null=True)
instance_class = models.CharField(max_length=200)
app2.models.py
class ImportJob(ParentImportJob):
"""
Class to store jobs of files being imported
Extends ParentImportJob
ParentImportJob is not abstract! But I am interested in 2 separated tables
"""
_imported_file = models.TextField(null=True,
blank=True,
db_column='imported_file')
import_result = models.TextField(null=True, blank=True)
def set_import_file(self, imported_file):
""" Set method for import_file field """
self._imported_file = base64.encodestring(imported_file)
def get_import_file(self, imported_file):
""" Set method for import_file field """
return base64.decodestring(self._imported_file)
imported_file = property(get_import_file, set_import_file)
The following recipe:
ob_mock = Recipe(ImportJob,
import_file=ofile.read(),
import_result=EXCEL_DICT)
When I ran self.job = mommy.make_recipe('excel2db.job_mock') inside the testcase I get IntegrityError: column user_id is not unique
I'm doing something wrong?