<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def restore(self, nosave=False):
 """Restore all of the object attributes to the attributes. Return the Django object. """

        if self.exists:
            obj = self.content_type.model_class().objects.get(uid=self.uid)
        else:
            obj = self.content_type.model_class()(uid=self.uid)
        for field in self.fields + self.foreignkeys:
            obj.__setattr__(field, self.get(field))
        if not nosave: obj.save()
        return obj