First of all, Klaus D. comment is correct: I also don't think that your design is correct. Instead of having Job
and TemporaryJob
models with similar fields you should only have a Job
model that has a boolean is_temporary
field that would be True
of this is a temporary job or False
if not. If you go this way then you wouldn't need to copy the values between tables. All other problems you'll experience will be resolved more easily if you have normalized data.
In any case, to actually answer your question, notice that objects.create()
is using kwargs (i.e it should be called like Job.objects.create(attr1=val1, att2=val2)
etc. The best way to output these kwargs is to create a dictionary with the values of the object you want to pass (the values of temporary_job_instance
) and pass it to create
using the unpacking syntax (**
). So, if values
is a dictionary with the values of temporary_job_instance
, you could just call Job.objects.create(**values)
.
Now you just need to create the values
dict from your temporary_job_instance
. Unfortunately, there's no easy way to do that in django :( It can be done though -- you can take a look at theses questions for some insight and a lot of methods of doing it: Convert Django Model object to dict with all of the fields intact or this Django: Converting an entire set of a Model's objects into a single dictionary