On 16 oct, 18:52, coderb <[EMAIL PROTECTED]> wrote:
> hi all,
>
> I'm having trouble with a category table when trying to add rows in
> admin
>
> my model is a Category table with a self reference using 'parent'
> which enables unlimited depth of categories. Its defined as follows:
>
> class Category(models.Model):
>     name        = models.CharField(max_length=100)
>     slug          = models.SlugField()
>     parent       = models.ForeignKey('self',default=1,null=True)
>     seq           = models.IntegerField(default=10)
>     active        = models.BooleanField(default=1)
>
>     def __unicode__(self):
>         return self.name
>
> (default=1,null=True option on parent was just a test for this issue)
>
> My problem is this:
> when trying to add a category in djangos standard admin, I keep
> getting an error that Parent is required. I guess Foreignkeys are
> always required.

Nope. You just have to add a 'blank=True' option, ie:

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

(snip)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to