Creating a Node in Django ORM

28 views
Skip to first unread message

Nafiul Islam

unread,
Jul 9, 2013, 9:07:29 AM7/9/13
to django...@googlegroups.com
How would you create a node using Django's ORM. This is what I mean: https://dpaste.de/JG52c/

Now, what I am basically trying to create is a liked list with nodes here.

Elliot Bradbury

unread,
Jul 9, 2013, 9:11:03 AM7/9/13
to django...@googlegroups.com
Check out django-mptt for creating parent/child (tree) relationships between models. https://github.com/django-mptt/django-mptt


On Tue, Jul 9, 2013 at 9:07 AM, Nafiul Islam <gamesb...@gmail.com> wrote:
How would you create a node using Django's ORM. This is what I mean: https://dpaste.de/JG52c/

Now, what I am basically trying to create is a liked list with nodes here.

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gamesbrainiac

unread,
Jul 9, 2013, 9:26:03 AM7/9/13
to django...@googlegroups.com
Thanks for answering, but is there a simple way that does not use a third-party library? I'd like to have as much control over this as possible.


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/wvXc7VehovQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Kind Regards,

Quazi Nafiul Islam

John

unread,
Jul 9, 2013, 9:35:01 AM7/9/13
to django...@googlegroups.com
Nafiul,

From your code snippet, it looks like you are trying to create a tree.
Look at django-mptt or google "django tree" for more information.

If you are trying to do a linked list, with 'previous' and 'next'
pointers, they just need to go in as foreign keys, but see
https://docs.djangoproject.com/en/1.5/ref/models/fields/#django.db.models.ForeignKey.related_name
because you will need to use the related_name attribute to make the
foreign key relationships distinct from each other. You will also need a
List object that holds the head (and perhaps tail) pointers for the list.

John

John

unread,
Jul 9, 2013, 9:41:04 AM7/9/13
to django...@googlegroups.com
Nafiul,

Either dig into the django-mptt code and pull out the bits you need, or look at MPTT and roll your own. http://www.sitepoint.com/hierarchical-data-database-2/ has a reasonable explanation (with code written in some archaic script ;) ) of how MPTT works.

John
Reply all
Reply to author
Forward
0 new messages