0

SGBD is PostgresSQL

I am using it to identify if there has been a change, if I would make an update in a date and time field, since once using auto_now = True it always enters my model and makes the update date field

print(address.save(force_update=True))

Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
mascDriver
  • 35
  • 9
  • `save()` doesn't return anything, so no you can't. But I don't understand your problem, can you maybe rephrase it, maybe English is not your native language but this sentence is hard to understand? An example would clarify it. – dirkgroten Dec 09 '19 at 13:55
  • tnks, my problem is i need to check if a table has changed in an update to apply a change to a time field – mascDriver Dec 09 '19 at 14:07
  • the only way is to fetch a fresh instance from the database and compare it to the current one before you save it. SQL doesn't tell you if a change was made when you `UPDATE` a row. – dirkgroten Dec 09 '19 at 14:12
  • Or, if you're interested in a specific field, look at [this](https://stackoverflow.com/questions/1355150/django-when-saving-how-can-you-check-if-a-field-has-changed) – dirkgroten Dec 09 '19 at 14:14
  • this was my fear, I thought that as django uses an abstract form it could return a rows_affected like the PDO to php – mascDriver Dec 09 '19 at 14:15
  • That would incur a cost, because it would have to fetch the "old" instance before updating it. How else could it tell what was changed? – dirkgroten Dec 09 '19 at 14:26
  • would be a form of an address, where it would change a time field every time that form was changed – mascDriver Dec 09 '19 at 14:31
  • I already gave you 2 ways to determine if it was changed. Try it. – dirkgroten Dec 09 '19 at 14:32
  • yes, very tnks. – mascDriver Dec 09 '19 at 14:45

0 Answers0