I have defined class Directory as follows:
class Directory(models.Model):
dir_name = models.CharField(max_length=100)
parent = models.ForeignKey("self", on_delete=models.CASCADE, null=True, blank=True)
def __str__(self):
return self.dir_name
When I enter a specific UI for the first time, the program will call a function in views.py to check if any directory exists, otherwise create the root directory:
root, created = Directory.objects.get_or_create(dir_name='media/', **insert null to foreign key**)
The reason of the above is that the root directory has no parent. How can I achieve this in django syntax? (I've tried something like parent='' and parent=null, but none of them worked). Thanks a lot in advance!
parent=None?