Issue 64: Working with inherited models
Status:  Invalid
Owner: ----
Closed:  Sep 2010
Reported by phoebebr...@gmail.com, Sep 30, 2009
Am trying to get mptt working with this model and no luck so far.  Not sure if this is because 
mptt doesn't understand inheritance or because i am doing something wrong.

Here is the model:

class Stuff(models.Model):
    name = models.CharField(max_length=140)
    parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
 
mptt.register(Stuff)
 

class ToDo(Stuff):
    what_type = models.CharField(max_length=1, choices=WHAT_TYPE, default='t')
    status = models.CharField(_('status'), max_length=1, choices=STATUS_CHOICES, default=1)

class Concept(Stuff):
    priority = models.CharField(_('status'), max_length=1, choices=PRIORITY_CHOICES, 
default='C')

And the code where I am saving (tried many different options!)

        obj = ToDo(**field_vals)
        obj.tags = " ".join(set(self.keyw_used))
        obj.save()
        
        # add parent
        if self.parent:
            obj.move_to(self.parent)

        obj.save()

Am getting the error  'Options' object has no attribute 'parent_attr' when trying to add to ToDo.
Error occurring here:
def is_root_node(self):
return getattr(self, '%s_id' % self._meta.parent_attr) is None 

although self does have mptt attributes:
>>> self.__dict__
{'rght': None, 'lft': None, 'stuff_ptr_id': 1L,  'parent_id': None, 'tree_id': None, .....  }


Sep 20, 2010
Project Member #1 craig.ds@gmail.com
The model inherits fields from the superclass, but the _meta doesn't inherit the fields. You need to call register() on every model, not just on the parent model.

This is avoided in the abstract-model-refactor branch, where register() has been removed and everything's done via inheritance from MPTTModel (see  Issue 34  )
Status: Invalid