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.
So what I tried was changing the parent to an integer,and entered
value  1 for parent.
then I changed parent back to a foreignkey and then in admin it worked
because parent value of 1 happened to be the same as the first
generated primary key value.
Of course this would not be the way to solve this issue, since I would
have the same issue every time I want to enter a top level category.
unless I create an initial top level dummy category called
'categories' which all top level categories will reference.

I'm not sure what the best practice approach is here, any advice would
be greatly appreciated.
if this a good appropach, then I need to also figure out how to
display the categories in a hierachy depending on their parent.

thanks




--~--~---------~--~----~------------~-------~--~----~
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