Fix django4.1 compatibility issues with related fields
In Django4.1 a ValueError exception is raised when trying to access to foreign keys for unsaved model instances:
This patch ensures that everything is saved before trying to use related models and handles the exception correctly in the Thread model pre_save.