V
V
Vadim kyklaed2018-06-22 11:04:24
Django
Vadim kyklaed, 2018-06-22 11:04:24

How to correctly pass the ID of the object to the link?

Good afternoon
, I have 2 views, one is the creation of an object through a form, and the second view provides saving files - it has two forejink fields for the object for which files are uploaded, and the second is the file upload field.
When drawing the form for creating an object, I also want to draw a link to create an object, but for this I need to pass the object ID to it, which I don’t have before the object is created.
What is the best way to organize this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tim, 2018-06-22
@kyklaed

Option 1:
You add two attributes to your object:
- draft = bool
- draft_created = datetime
When you open the form to create an object, you already create it in the database with the date and True value. In this case, you will have an ID. Wherever garbage is not needed, you can filter by draft = False. And in order not to clog the database, you can once in a certain period of time go through a script called by a cron job and delete everything that draft=True and the creation date was yesterday.
Upload files without reference to the project, but keep a list of their IDs on the form. And when you create an object, go through the files and give them IDs.

D
Denis Melnikov, 2018-06-22
@Mi11er

Well, as an idea:
Get settlements ID ?) and add 1 =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question