Django refresh_from_db for ForeignKey
AFAIK In django, Till now refresh_from_db
will not update data for relational fields.It only check whether relation is removed or not. But you can do like (as you did).
for i in container_product._meta.concrete_fields:
if i.is_relation:
getattr(container_product, i.name).refresh_from_db()
OR override refresh_from_db
class Mymodel(models.Model):
def refresh_from_db(self, using=None, fields=None):
super(Mymodel, self).refresh_from_db(using=None, fields=None)
for i in self._meta.concrete_fields:
if i.is_relation and getattr(self, i.name):
getattr(self, i.name).refresh_from_db()