1

This is a newbie question, but despite reading https://docs.djangoproject.com/en/dev/ref/models/instances/#saving-objects , I'm not quite sure how to do this. I have an existing table where I would like to iterate through all its records, and save certain info to a second table. I have the following model:

class myEmails(models.Model):
    text = models.CharField(max_length=1200)

In my view I have:

def getMyMessages(request):    

    from django_mailbox.models import Message
    from get_new_emails.models import myEmails
    import re    

    qs = Message.objects.all()
    count = 0
    output = ""
    for i in qs:
        count += 1
        output = output + str(count) + " TEXT: " + i.text + '<br>' + '<br>'    

    return HttpResponse(output)

How can I modify my view to save "i.text" to the text field of the 'myEmails' table

1 Answer 1

2

You can create new objects and save them to the database afterwards using save():

for i in qs:
    obj = myEmails(text=i.text)
    obj.save()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.