You can pass in the name of a model as a string to ForeignKey and it will do the right thing.
So:
parent = models.ForeignKey("CategoryModel")
Or you can use the string “self”
parent = models.ForeignKey("self")
More Related Contents:
- Convert Django Model object to dict with all of the fields intact
- What’s the difference between select_related and prefetch_related in Django ORM?
- Django Aggregation: Summation of Multiplication of two fields
- How to create an object for a Django model with a many to many field?
- How to execute a GROUP BY … COUNT or SUM in Django ORM?
- Django orm get latest for each group
- LEFT JOIN Django ORM
- Serializing Foreign Key objects in Django
- Django Blob Model Field
- Direct assignment to the forward side of a many-to-many set is prohibited. Use emails_for_help.set() instead
- How to perform OR condition in django queryset?
- What is the default order of a list returned from a Django filter call?
- django order_by query set, ascending and descending
- Set Django’s FileField to an existing file
- Sorting related items in a Django template
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
- Django – The included urlconf doesn’t have any patterns in it
- How does Django handle multiple requests?
- How to upload multiple files in django rest framework
- How to run cloned Django project?
- How to Copy/Clone a Virtual Environment from Server to Local Machine
- How to create list field in django
- Install mod_wsgi on Ubuntu with Python 3.6, Apache 2.4, and Django 1.11
- How to resize an ImageField image before saving it in python Django model
- No web processes running Error – Deploying Django on Heroku
- ImportError: No module named objectid
- Single Table Inheritance in Django
- Django: How to create a model dynamically just for testing
- How to implement a “back” link on Django Templates?
- Override existing Django Template Tags