I am begin to Django and I start create a simple personal blog. I want to create model Category that related to parrent Category. I have read about display Foreign Key's choices in django-admin. It only work with some static choices. But I cannot query data from database for choices. This is how I am trying to do:
class Category (models.Model):
name = models.CharField(max_length=255)
slug = models.CharField(unique=True, blank=True, max_length=255)
parent_category = models.CharField(max_length=255, blank=True, choice = CATEGORIES_CHOICE)
I want CATEGORIES_CHOICE = Category.object.all()
. Any one have an idea to resolve this problem?
You can use a django self-referential foreign key !
or
it's exactly the same