I'm using Django 1.6 RC1 and Python 3.3 with the following models:
-- class StepBlueprint(models.Model):
parents = models.ManyToManyField('self', blank=True, null=True, related_name='children')
name = models.CharField( max_length=100 )
def __str__(self):
return self.name
class FlowBlueprint(StepBlueprint):
description = models.TextField()
def get_children(self):
print("DEBUG: processing ({0})".format(self))
print(dir(self))
# why isn't this working?? this is what related_name is supposed to provide
return self.children
When I call get_children() here, I get the following:
DEBUG: processing (Prodigal)
['DoesNotExist', 'MultipleObjectsReturned', 'TYPES', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_base_manager', '_default_manager', '_deferred', '_do_insert', '_do_update', '_get_FIELD_display', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_get_unique_checks', '_meta', '_perform_date_checks', '_perform_unique_checks', '_save_parents', '_save_table', '_set_pk_val', '_state', 'build', 'clean', 'clean_fields', 'commandblueprint', 'conditional_code', 'date_error_message', 'delete', 'description', 'flow_set', 'flowblueprint', 'full_clean', 'get_children', 'get_command', 'get_type_display', 'id', 'name', 'objects', 'parents', 'pk', 'prepare_database_save', 'save', 'save_base', 'serializable_value', 'standalonetool_set', 'stepblueprint_ptr', 'stepblueprint_ptr_id', 'type', 'unique_error_message', 'validate_unique']
Traceback (most recent call last):
[ call stack ... ]
return self.children
AttributeError: 'FlowBlueprint' object has no attribute 'children'
What am I doing wrong here? From within the FlowBlueprint object I want to be able to get the backwards relation of all those objects pointing to it, and it seems like related_name is supposed to provide that. Its value doesn't show up in the dir() output.
Any help would be greatly appreciated.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6ae3bcd5-ebc1-4284-a3b8-f4c2866a9b0b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment