Django Inheritance Issues -
okay, have been reading other django inheritance questions , can't find help. may have understanding issue how inheritance works. here issue. start, have 2 base models i'd of other models inherit from. base model contains useful methods of models. second start of account specific object.
class basemodel(models.model): # couple of methods models need have. no fields. class accountmodel(models.model): ''' base model items related specific account''' account = models.foreignkey(account) def save(self, request, *args, **kwargs): self.account = request.session['account'] super(accountmodel, self).save(*args, **kwargs)
then have 3 models:
class keyword(accountmodel) : keyword = models.charfield(max_length=300) #other fields, none required... class project(accountmodel) : project_name = models.charfield(max_length=200,verbose_name="project name") #other fields.. class keywordtarget(basemodel): keyword = models.foreignkey(keyword) url = models.urlfield(null=true,blank=true) project = models.foreignkey(project)
but when try create new keyword, error:
valueerror: cannot assign "'something'": "keyword.keyword" must "keyword" instance.
when do:
kw = keyword(keyword = "something")
where going wrong?
(also, please don't tell me should using manytomany through unless solves problem @ hand)
it looks both basemodel , account model abstract, should specify in models' meta objects like:
class basemodel(models.model): ... class meta: abstract=true
(see http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes)
i'm guessing without that, you're ending interference between inheriting models.
Comments
Post a Comment