django field value question.

Asked 2 years ago, Updated 2 years ago, 42 views

Hi, everyone. It's a django question.

x = models.CharField()
y = models.CharField()

There are two fields and each field has a

id = 1
x = "Hong Gil Dong"
y = ["Apple", "Melon", "Watermelon"]

It is saved as shown in .

I'm going to store it by matching one x value to one of the values in the list y as shown below.

id = 1
x = "Hong Gil Dong"
y = "Apple"

id = 2
x = "Hong Gil Dong"
y = "Melon"

id = 3
x = "Hong Gil Dong"
y = "Watermelon"

I want to process it like this and save it in db, what should I do?

django python

2022-09-22 16:59

1 Answers

Turn the repeat statement by the length of y, and replace the values (id, x, y[index]) with the insert statement inside the repeat statement. Currently, the id value is fixed, so please increase the id value at the bottom of the repeat statement.


2022-09-22 16:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.