Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there's no Field object with this name on the model, return the model attribute's value. Used to serialize a field's value (in
(self, field_name)
| 814 | ) |
| 815 | |
| 816 | def serializable_value(self, field_name): |
| 817 | """ |
| 818 | Return the value of the field name for this instance. If the field is |
| 819 | a foreign key, return the id value instead of the object. If there's |
| 820 | no Field object with this name on the model, return the model |
| 821 | attribute's value. |
| 822 | |
| 823 | Used to serialize a field's value (in the serializer, or form output, |
| 824 | for example). Normally, you would just access the attribute directly |
| 825 | and not use this method. |
| 826 | """ |
| 827 | try: |
| 828 | field = self._meta.get_field(field_name) |
| 829 | except FieldDoesNotExist: |
| 830 | return getattr(self, field_name) |
| 831 | return getattr(self, field.attname) |
| 832 | |
| 833 | def save( |
| 834 | self, |
no test coverage detected