1

Ok! I have this model:

class my(models.Model):
    name = models.TextField()
    description = models.TextField()
    created = models.DateTimeField()
    def __unicode__(self):
       return self.name

I'm gettin data to this model from mssql database and saving it. Something like this.

mysql_name='somedata'           #this data come from some connection with mssql
mssql_description='somedata'    #this data come from some connection with mssql
mssql_created='somedata'        #this data come from some connection with mssql

i'm creating field in my MySQL database and saving

mymodel=my(name=mysql_name, description=mssql_description, created=mssql_created)

mymodel.save()

Now it is in my database. I'm doing this in loop so it fill my database.

Then i need check the data in remote MSSQL server by using timestamp. I made SQL request So i'm getting only updated data. End I have to overwrite old data.

Question is how to overvrite old data? I'm little bit confuse.

could it be like this?

   mymodel=my.objects.get(name=mysql_Name)
   mymodel.description=new_updated_description
   mymodel.save

but if i do not have this field at all?....

I have to chek if i have it in my databse? How....?

2 Answers 2

1

As long as the same PK is used, the row will be overwritten. It is easiest to get() the existing row, modify the fields, and save() it.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use get_or_create on your models manager as a shortcut to create new instance of the model or to update the existing one. See docs for examples.

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.