The parent object knows about all it's children. Each parent instance
has a 'manager' for the set of children, like
parent_instance.mychildren_set.
More exactly:
activity = Activity.objects.get(id=someid)
activity_parts = activity.activitypart_set.all() # you can use .filter
() etc.
And I'm not sure why you need the order, since they will be already
ordered by primary key (the most recent activity part added will have
highest primary key), and you can just use that.
scelerat wrote:
> I've got a part/collection pairing of objects tables, and I'd like to
> know the best way to manage the order of things inside the table.
>
> Briefly:
>
> class Activity(models.Model):
> # etc...
>
> class ActivityPart(models.Model):
> order = models.IntegerField("order in parent", default=1)
> activity = models.ForeignKey( Activity )
> # etc.
>
> What I want to do is, upon creation of an ActivityPart, figure out the
> other parts already pointing to an Activity, and increase the order
> number before saving the part if there are already ones with that
> number. I also want the parent object to know about all its Parts. I'm
> not sure what the best way to do either of these is... it seems like I
> could do some or all of this in the ArrayPart's __init__ method, but
> maybe there's a more Django-ish way?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---