(cls, pk, **kwargs)
| 92 | |
| 93 | @classmethod |
| 94 | def update(cls, pk, **kwargs): |
| 95 | instance = cls.objects.get(pk=pk) |
| 96 | |
| 97 | if instance.locked: |
| 98 | allowed_fields = {"user_agent_id"} # Only allow updating this field |
| 99 | |
| 100 | for field_name, new_value in kwargs.items(): |
| 101 | if field_name not in allowed_fields: |
| 102 | raise ValidationError( |
| 103 | f"Cannot modify {field_name} on a protected profile." |
| 104 | ) |
| 105 | |
| 106 | # Ensure user_agent ForeignKey updates correctly |
| 107 | if field_name == "user_agent" and isinstance( |
| 108 | new_value, cls._meta.get_field("user_agent").related_model |
| 109 | ): |
| 110 | new_value = new_value.pk # Convert object to ID if needed |
| 111 | |
| 112 | setattr(instance, field_name, new_value) |
| 113 | |
| 114 | instance.save() |
| 115 | return instance |
| 116 | |
| 117 | def is_proxy(self): |
| 118 | if self.locked and self.name == PROXY_PROFILE_NAME: |
no test coverage detected