in Education by
Table1 where i get the data from a management script that calls a certain API. Table2 also gets data from an Api. The scenario is xid & kid are same, so i have implemented a OneToOne relationship so that i can easily get the related item from table1 in context of table2. Table1 has to be populated in order to populate table1, as only then assignment of table2 instance can be done. 5687 Already exists in table1 but still i get the error: ValueError: Cannot assign "5687": "Table2.kid" must be a "Table1" instance. Models.py class Table1(models.Model): xid = models.IntegerField(primary_key=True) amount = models.IntegerField() class Table2(models.Model): kid = models.OneToOneField(Table1,primary_key=True, on_delete=models.CASCADE) vid = models.IntegerField(null=True, blank=True) g_amount = models.IntegerField() This is my script code that is same for both management commands that get me data. Management/commands/script.py """ API CODE """ data = { 'kid': kid, 'vid': vid, 'g_amount': g_amount } if Table2.objects.filter(vid=xid).exists() or Table1.objects.filter(xid=kid).exists() is False: continue else: # print(data) instance = Table2(**dataff) instance.save() Or should is there a way i don't need to have OneToOne relationship. Using Django's ORM a query can be constructed that will get combine the instance from these two table in one and place it in a Virtual Table so that i don't loose ORM capabilities. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The conditional check on models field is applied after declaring the data dict. It will be declared after the if condition so that the dict can be saved with condition.

Related questions

0 votes
    Is it possible to assign the field type dynamically - Django Form? field_type = 'CharField' field = forms. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Is it possible to assign the field type dynamically - Django Form? field_type = 'CharField' field = forms. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Working on a project using sqlServer 2008. EDIT for clarification : table 1 contains 1 field that has to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    when i want to execute below code and plot figer scatter_matrix(total_frame) total_frame is a dataframe like ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    In this data file, the United States is broken up into four regions using the "REGION" column. Create a query ... for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 17, 2021 in Education by JackTerrance
0 votes
    I have been wrestling with this for a while. I am trying to parse a JSON Api into a UITableview. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Once the lower-level lock is released, the operation cannot be undone by using the old values of updated ... and Undo Operations in division Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    Which of these instance cannot be created? (a) Integer instance (b) Generic class instance (c) Generic type ... Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these instance cannot be created? (a) Integer instance (b) Generic class instance (c) Generic ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Penny has 5 children, 1st is January, 2nd kid February, 3rd is called march , 4th is April. What is the name of the 5th....
asked Feb 11, 2021 in Education by JackTerrance
0 votes
    What is a collection of facts referring to a single entity, object or a person? 1)Table 2)Field 3)Record 4)None of the above Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    What is the problem Here ? I got an error shows ValueError: too many values to unpack This code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am receiving the error: ValueError: Wrong number of items passed 3, placement implies 1, and I am struggling to ... 'sigma'] = sigma Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    def multiple_dfs(xyz_file, sheet, *args): row=2 writer = pd.ExcelWriter(xyz_file, engine='openpyxl') df = pd. ... help me over this? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    b. Write a java statement to accomplish each of the following tasks: i. Declare a variable, sum and a to be ... value of variable sum. Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
...