So if I have a simple model that I want as a source of my PK like so:
class PostCreation(models.Model):
pk = models.AutoField(primary_key=True)
post = models.OneToOneField(Post, on_delete=models.CASCADE)
What I want to do is create a PK of a blog post before the post has been created. My reasoning is I want the images/files I upload to be in a format of
/media/blogPK/files
So my Post will have a id/PK field set from the PostCreation class above And the Pseudo code is below:
id = PostCreation()
FileField(upload_to='{}{}{}'.format(id, '/', files))
But how can I create the PK first and then pass it to my Post model and then set the Post is/pk to that of PostCreation?
I's going to be using ModelForm to output the fields for the Post content, Description/Date etc so when I goto visit that view I want the pk/id already made even if the user does submit the content of the Post model.
How can I do this? Is it possible?
Thx