To create a table by copying and modifying a specific table in the Django model

Asked 2 years ago, Updated 2 years ago, 55 views

Hello. This is a question for Jango model.


class EnActress(models.Model):
    name = models.CharField(max_length=100, null=True)

After modifying the data in the name field in the above model (data in the name field exists)


class EnActress(models.Model):
    name = models.CharField(max_length=100, null=True)
    name_modify = models.CharField(max_length=100, null=True)

You want the name_modify field to have the modified data of the name field added as shown in . I want the data order to be the same as the name field, so which method should I use??

django python

2022-09-22 21:26

1 Answers

I think we can run the following code on the long shell.

Instead of +"hello", you can process actress.name and put it in name_modify.

for actress in EnActress.objects.all():
    actress.name_modify = actress.name + "hello"
    actress.save

If you're not familiar with shell, see This lecture.


2022-09-22 21:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.