DRF Serializers
Account serializers for Smarter API.
- class smarter.apps.account.serializers.AccountContactSerializer(*args, **kwargs)[source]
Bases:
SmarterCamelCaseSerializerSerializer for the AccountContact model in the Smarter API.
This serializer exposes all fields of the AccountContact model, including a minimal account reference. Use it for endpoints that manage or display account contact information.
- Parameters:
account – Instance of
AccountMiniSerializer. Minimal account information.... – All other fields as defined in the AccountContact model.
Note
All fields are read-only in this serializer.
Example usage:
from smarter.apps.account.serializers import AccountContactSerializer serializer = AccountContactSerializer(contact_instance) data = serializer.data
See also
For full account details, use
AccountSerializer.- get_fields()[source]
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- class smarter.apps.account.serializers.AccountMiniSerializer(*args, **kwargs)[source]
Bases:
SmarterCamelCaseSerializerSerializer for a minimal representation of the Account model in the Smarter API.
This serializer is intended for scenarios where only the account number is required, such as embedding account references in related resources or optimizing API payload size.
- Parameters:
account_number – String. The unique identifier for the account.
Note
Only the
account_numberfield is included in serialization.Tip
Use this serializer for nested relationships or summary views.
Example usage:
from smarter.apps.account.serializers import AccountMiniSerializer serializer = AccountMiniSerializer(account_instance) data = serializer.data
See also
For full account details, use
AccountSerializer.
- class smarter.apps.account.serializers.AccountSerializer(*args, **kwargs)[source]
Bases:
MetaDataModelSerializerSerializer for the Account model in the Smarter API.
This serializer provides full access to all fields of the Account model, making it suitable for detailed account data retrieval and updates via API endpoints.
- Parameters:
account_number – String. The unique identifier for the account.
name – String. The account name.
... – Other fields as defined in the Account model.
Important
All fields in the Account model are included in serialization and deserialization.
Example usage:
from smarter.apps.account.serializers import AccountSerializer serializer = AccountSerializer(account_instance) data = serializer.data
See also
For lightweight account representations, use
AccountMiniSerializer.
- class smarter.apps.account.serializers.BudgetSerializer(*args, **kwargs)[source]
Bases:
MetaDataModelSerializerSerializer for the
Budgetmodel, with the number of resources it is attached to, and of those it locks.Example usage:
from smarter.apps.account.serializers import BudgetSerializer data = BudgetSerializer(budget).data
- get_manifest_url(obj)[source]
The URL of the Budget’s detail view, which renders its manifest.
- Return type:
- class smarter.apps.account.serializers.ChargeSerializer(*args, **kwargs)[source]
Bases:
SmarterCamelCaseSerializerRead-only serializer for the
Chargemodel.This serializer converts
Chargemodel instances to and from the JSON representation used by the Smarter API. Field names are automatically converted between Django’ssnake_caseconvention and the API’scamelCaseconvention by theSmarterCamelCaseSerializerbase class.This serializer is intended for read operations only. All model fields are exposed, and every field is marked as read-only, preventing creation or modification through this serializer.
- Inherits:
SmarterCamelCaseSerializer
- class smarter.apps.account.serializers.MetaDataWithOwnershipModelSerializer(*args, **kwargs)[source]
Bases:
MetaDataModelSerializerSerializer for models that extend MetaDataWithOwnershipModel, adding an ‘account’ field.
It also adds
can_delete, which is True if the authenticated user may delete the resource now: they have ownership permission for it, and no other resource depends on it. Subclasses setMeta.kindto the resource’s SAM kind, whichcan_deleteneeds to find its broker. Every subclass includes it, whatever itsMeta.fields.- get_can_delete(obj)[source]
Return True if the authenticated user may delete the resource now.
The user can delete the object if a.) they have permission and b.) no dependencies existing on the object based on the SAMBroker enforcement rules.
The user must have ownership permission for the resource, as in
MetaDataWithOwnershipModelManager.with_ownership_permission_for(), and no other resource may depend on it, as inAbstractBroker.dependencies().Note
This builds a broker, and queries its dependencies, for each resource that the user may delete. Serializing a long list of resources is correspondingly slower.
- Parameters:
obj (MetaDataWithOwnershipModel) – The resource.
- Returns:
Whether the user may delete the resource. False if the serializer has no request in its context, or does not know the resource’s kind. See
user_can_delete().- Return type:
- class smarter.apps.account.serializers.UserMiniSerializer(*args, **kwargs)[source]
Bases:
SmarterCamelCaseSerializerSerializer for a minimal representation of the User model in the Smarter API.
This serializer is designed for use cases where only essential user information is required, such as listing users or embedding user data in related resources.
- Parameters:
username – String. The user’s username.
email – String. The user’s email address.
Note
All fields are read-only and included in the serialized output.
Tip
Use this serializer for lightweight API responses to reduce payload size.
Example usage:
from smarter.apps.account.serializers import UserMiniSerializer serializer = UserMiniSerializer(user_instance) data = serializer.data
See also
For full user details, use
UserSerializer.
- class smarter.apps.account.serializers.UserProfileSerializer(*args, **kwargs)[source]
Bases:
SmarterCamelCaseSerializerSerializer for the UserProfile model in the Smarter API.
This serializer provides a minimal representation of a user profile, including nested user and account data. Use it for endpoints where a summary of user and account relationships is required.
- Parameters:
user – Instance of
UserMiniSerializer. Minimal user information.account – Instance of
AccountMiniSerializer. Minimal account information.
Note
Only the
userandaccountfields are included in serialization.Example usage:
from smarter.apps.account.serializers import UserProfileSerializer serializer = UserProfileSerializer(profile_instance) data = serializer.data
See also
For more detailed user or account data, use
UserSerializerorAccountSerializer.
- class smarter.apps.account.serializers.UserSerializer(*args, **kwargs)[source]
Bases:
MetaDataModelSerializerSerializer for the User model in the Smarter API.
This serializer converts Django User model instances to and from JSON using camelCase field names, making it suitable for API responses and requests.
- Parameters:
id – Integer. The unique identifier for the user.
username – String. The user’s username.
first_name – String. The user’s first name.
last_name – String. The user’s last name.
email – String. The user’s email address.
is_staff – Boolean. Indicates if the user has staff privileges.
is_superuser – Boolean. Indicates if the user has superuser privileges.
Note
All fields listed in
fieldsare included in serialization. Add more fields to the list if needed.Example usage:
from smarter.apps.account.serializers import UserSerializer serializer = UserSerializer(user_instance) data = serializer.data
- smarter.apps.account.serializers.user_can_delete(obj, kind, user)[source]
Return True if a user may delete a resource now.
The user must have ownership permission for the resource, as in
MetaDataWithOwnershipModelManager.with_ownership_permission_for(), and no other resource may depend on it, as inAbstractBroker.dependencies(). It is thecanDeleteof the resource’s api responses, e.g.MetaDataWithOwnershipModelSerializer.get_can_delete().Note
This builds a broker, and queries its dependencies. Checking a long list of resources is correspondingly slower.
- Parameters:
obj (MetaDataWithOwnershipModel) – The resource.
kind (
str|None) – The resource’s SAM kind, e.g. LLMClient, which finds its broker.user (
object) – The user, e.g. the request’s user. Anything that is not aUser, e.g. an anonymous user or None, may delete nothing.
- Returns:
Whether the user may delete the resource.
- Return type: