| Issue 64: | Working with inherited models | |
| 2 people starred this issue and may be notified of changes. | Back to list |
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
Status:
Invalid
|