You want:

parent = models.ForeignKey('self', null=True, blank=True)

On Jun 21, 3:37 pm, Magnus Valle <wisca...@gmail.com> wrote:
> Hi,
> I'm trying to make model that has itself as a foreign key, in an
> attempt to store a reverse tree in Django.
> However, I can't find a way to set a default value to
> models.ForeignKey or make it optional.
>
> My model is like this:
> class Node(models.Model):
>     name = models.CharField(max_length=100)
>     parent = models.ForeignKey('self')
>
> runserver doesn't complain, but whenever I try to enter data to the
> model with Django's admin interface I get a "This field is required."
> message, and it want's me to select a entry, but there are none.
>
> --
> Magnus

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to