954 | | try: |
955 | | # Object instance wasn't passed in -- must be an ID. |
956 | | val = kwargs.pop(f.attname) |
957 | | except KeyError: |
958 | | val = f.get_default() |
959 | | else: |
960 | | # Object instance was passed in. |
961 | | # Special case: You can pass in "None" for related objects if it's allowed. |
962 | | if rel_obj is None and f.null: |
963 | | val = None |
964 | | else: |
965 | | try: |
966 | | val = getattr(rel_obj, f.rel.get_related_field().attname) |
967 | | except AttributeError: |
968 | | raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) |
969 | | setattr(self, f.attname, val) |
| 957 | val = f.get_default() |
971 | | val = kwargs.pop(f.attname, f.get_default()) |
972 | | setattr(self, f.attname, val) |
973 | | if kwargs: |
974 | | raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] |
| 959 | # Object instance was passed in. |
| 960 | # Special case: You can pass in "None" for related objects if it's allowed. |
| 961 | if rel_obj is None and f.null: |
| 962 | val = None |
| 963 | else: |
| 964 | try: |
| 965 | val = getattr(rel_obj, f.rel.get_related_field().attname) |
| 966 | except AttributeError: |
| 967 | raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) |
| 968 | setattr(self, f.attname, val) |
| 969 | else: |
| 970 | val = kwargs.pop(f.attname, f.get_default()) |
| 971 | setattr(self, f.attname, val) |
| 972 | if kwargs: |
| 973 | raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] |