UserProfile Model
Account UserProfile model.
- class smarter.apps.account.models.user_profile.SmarterBaseModelManager(*args, **kwargs)[source]
Bases:
ManagerCustom manager for MetaDataWithOwnershipModel that returns a SmarterBaseQuerySetWithPermissions to enable permission-based filtering by user_profile.
- alias(*args, **kwargs)[source]
Returns a SmarterBaseQuerySetWithPermissions with alias applied.
- Return type:
- annotate(*args, **kwargs)[source]
Returns a SmarterBaseQuerySetWithPermissions with annotate applied.
- Return type:
- complex_filter(filter_obj)[source]
Returns a SmarterBaseQuerySetWithPermissions with the applied complex filter.
- Return type:
- difference(*other_qs)[source]
Returns a SmarterBaseQuerySetWithPermissions representing the difference of querysets.
- Return type:
- distinct(*field_names)[source]
Returns a SmarterBaseQuerySetWithPermissions with distinct applied.
- Return type:
- exclude(*args, **kwargs)[source]
Returns a SmarterBaseQuerySetWithPermissions with the applied exclusion.
- Return type:
- filter(*args, **kwargs)[source]
Returns a SmarterBaseQuerySetWithPermissions with the applied filter.
- Return type:
- intersection(*other_qs)[source]
Returns a SmarterBaseQuerySetWithPermissions representing the intersection of querysets.
- Return type:
- order_by(*field_names)[source]
Returns a SmarterBaseQuerySetWithPermissions with order_by applied.
- Return type:
- Overloads:
self, clear (None) → SmarterBaseQuerySetWithPermissions[_GenericTypeVar]
self, lookups (str | Prefetch) → SmarterBaseQuerySetWithPermissions[_GenericTypeVar]
Returns a SmarterBaseQuerySetWithPermissions with prefetch_related applied.
- select_for_update(**kwargs)[source]
Returns a SmarterBaseQuerySetWithPermissions with select_for_update applied.
- Return type:
- Overloads:
self, clear (None) → SmarterBaseQuerySetWithPermissions[_GenericTypeVar]
self, fields (str) → SmarterBaseQuerySetWithPermissions[_GenericTypeVar]
Returns a SmarterBaseQuerySetWithPermissions with select_related applied.
- union(*other_qs, all=False)[source]
Returns a SmarterBaseQuerySetWithPermissions representing the union of querysets.
- Return type:
- with_ownership_permission_for(user)[source]
Returns a queryset of resources that the authenticated user in the given request has full management (ownership) permission for.
Permission logic:
If the user is not authenticated, they have no access.
If the user is a superuser, they have ownership permission for all resources.
- If the user is a staff user, they have ownership permission for resources that are:
Owned by their UserProfile, OR
Owned by any UserProfile within their Account.
If the user is a regular authenticated user, they have ownership permission only for resources they own.
- Parameters:
user (
User) –django.contrib.auth.models.UserThe user to check.- Return type:
- Returns:
django.db.models.QuerySetA queryset of this resource if the user has permission to fully manage it, or an empty queryset if not.
- with_read_permission_for(user)[source]
A custom Smarter pipeline for filtering any MetaDataWithOwnership queryset based on the Smarter permissions scheme for the authenticated user in the given request.
Returns a queryset of the resource if the user has permission to read it, or an empty queryset if not.
Permission logic:
If the user is not authenticated, they have no access.
If the user is a superuser, they have access to all resources.
- If the user is a regular authenticated user, they have access to resources that are:
Owned by their UserProfile, OR
Owned by their Account admin UserProfile, OR
Owned by the Smarter admin UserProfile.
- Parameters:
user (
User) –django.contrib.auth.models.UserThe user to check.queryset – Optional[
django.db.models.QuerySet] An optional queryset to filter. If not provided, the method will default to filtering all instances
- Return type:
- Returns:
django.db.models.QuerySetA queryset of this resource if the user has permission to read it, or an empty queryset if not.
- class smarter.apps.account.models.user_profile.SmarterBaseQuerySetWithPermissions(model=None, query=None, using=None, hints=None)[source]
Bases:
QuerySetCustom queryset for permission-based resource filtering by user profile.
This queryset adds permission-aware filtering for resources owned by a specific user profile.
See also
Django: Creating a manager with QuerySet methods <https://docs.djangoproject.com/en/6.0/topics/db/managers/#creating-a-manager-with-queryset-methods>_
django-stubs: Custom QuerySets <https://github.com/typeddjango/django-stubs>_
- with_ownership_permission_for(user)[source]
Returns a queryset of resources that the authenticated user in the given request has full management (ownership) permission for.
Only users with staff or superuser status are permitted to manage resources.
- Parameters:
user (
User) –django.contrib.auth.models.UserThe user to check.- Return type:
- Returns:
django.db.models.QuerySetA queryset of this resource if the user has permission to fully manage it, or an empty queryset if not.
- with_read_permission_for(user)[source]
A pipeline for filtering a queryset of this resource based on the permissions of the authenticated user in the given request.
Return a queryset of this resource if the user has permission to read it, or an empty queryset if not.
- Parameters:
user (
User) –django.contrib.auth.models.UserThe user to check.queryset – Optional[
django.db.models.QuerySet] An optional queryset to filter. If not provided, the method will default to filtering all instances
- Return type:
- Returns:
django.db.models.QuerySetA queryset of this resource if the user has permission to read it, or an empty queryset if not.
- class smarter.apps.account.models.user_profile.UserProfile(*args, **kwargs)[source]
Bases:
MetaDataModelUserProfile model for associating Django users with Smarter accounts.
Establishes a link between a Django User and an Account, enabling centralized management of billing, identity, and resource ownership.
- Parameters:
user – ForeignKey to
django.contrib.auth.models.User. The user associated with this profile.account – ForeignKey to
Account. The related Smarter account.is_test – Boolean. Indicates if this profile is for testing purposes.
Important
The combination of user and account must be unique. Duplicate profiles for the same user and account are not allowed.
Example usage:
from smarter.apps.account.models import UserProfile profile = UserProfile.objects.create(user=user, account=account) profile.add_to_account_contacts(is_primary=True)
- Parameters:
id (Unknown) – Primary key: ID
created_at (Unknown) – Created at
updated_at (Unknown) – Updated at
name (Unknown) – Name. Name in camelCase, e.g., ‘apiKey’, no special characters.
description (Unknown) – Description. A brief description of this resource. Be verbose, but not too verbose.
version (Unknown) – Version. Semantic version in the format MAJOR.MINOR.PATCH, e.g., ‘1.0.0’.
annotations (Unknown) – Annotations. Key-value pairs for annotating this resource.
profile_image_url (Unknown) – Profile image url. URL to the user’s profile image, provided via oauth.
Relationship fields:
- Parameters:
tags (Unknown) – Tags. Tags for categorizing and organizing this resource. (related name:
userprofile)tagged_items (Unknown) – Tagged items (related name:
+)
Reverse relationships:
- Parameters:
smarterauthtoken (Unknown) – All API Keys of this user profile (related name of
user_profile)charge (Unknown) – All charge of this user profile (related name of
user_profile)llmclient (Unknown) – All LLMClients of this user profile (related name of
user_profile)connectionbase (Unknown) – All connection bases of this user profile (related name of
user_profile)pluginmeta (Unknown) – All Plugins of this user profile (related name of
user_profile)prompt (Unknown) – All Chats of this user profile (related name of
user_profile)provider (Unknown) – All Providers of this user profile (related name of
user_profile)secrets (Unknown) – All secrets of this user profile (related name of
user_profile)vectorestoremeta (Unknown) – All Vectorstore Metadata of this user profile (related name of
user_profile)
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- exception NotUpdated
Bases:
ObjectNotUpdated,DatabaseError
- account
-
Account (related name:
user_profiles)- Type:
Type
- add_to_account_contacts(is_primary=False)[source]
Add the user to the account’s contact list.
Creates or updates an AccountContact entry for the user, ensuring their email and name are registered with the account. Optionally sets the contact as primary.
- Parameters:
is_primary (
bool) – Boolean. If True, marks the contact as the primary contact for the account. Defaults to False.
Important
Ensures every user associated with an account is also listed as a contact, supporting notifications and account management.
Example usage:
profile.add_to_account_contacts(is_primary=True)
See also
AccountContact
- classmethod admin_for_account(account)[source]
Return the designated user for the given account.
This method finds the first staff user associated with the account. If no staff user exists, it returns the first available user. If the account has no users, an admin user is created and returned.
- Parameters:
account (
Account) – Instance ofAccount. The account for which to find the designated user.- Return type:
- Returns:
django.contrib.auth.models.UserThe designated user for the account.
Attention
If no staff or regular users exist for the account, an admin user is automatically created. You must set the password manually.
Error
Logs an error if no admin or user is found for the account.
Example usage:
user = UserProfile.admin_for_account(account)
See also
- property cached_account: Account
Retrieve the associated Account instance with caching. This significantly reduces the number of database queries when accessing the account from the user profile.
- Returns:
Account The associated Account instance.
Example usage:
account = user_profile.cached_account if account: print(account.company_name)
- property cached_user: User
Retrieve the associated User instance with caching. This significantly reduces the number of database queries when accessing the user from the user profile.
- Returns:
User The associated User instance.
Example usage:
user = profile.cached_user if user: print(user.email)
- charge
Reverse
ForeignKeyfromChargeAll charge of this user profile (related name of
user_profile)- Type:
Type
- connectionbase_set
Reverse
ForeignKeyfromConnectionBaseAll connection bases of this user profile (related name of
user_profile)- Type:
Type
- created_at
-
Created at
Timestamp indicating when the model instance was created.
This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.
- Type:
Type
- description
-
Description. A brief description of this resource. Be verbose, but not too verbose.
- Type:
Type
- classmethod get_cached_object(*args, invalidate=False, pk=None, name=None, user=None, username=None, account=None, **kwargs)[source]
Retrieve a model instance by primary key or name, using caching to optimize performance. This method is selectively overridden in models that inherit from MetaDataModel to provide class-specific function parameters.
Example usage:
# Retrieve by primary key instance = MyModel.get_cached_object(pk=1) # Retrieve by name instance = MyModel.get_cached_object(name="exampleName")
- Parameters:
- Returns:
The model instance if found, otherwise None.
- Return type:
- classmethod get_cached_objects(invalidate=False, user=None, **kwargs)[source]
Retrieve a queryset of UserProfile instances associated with the given user, using caching to optimize performance.
- Parameters:
- Returns:
QuerySet[UserProfile]. A queryset of UserProfile instances associated with the given user, or all profiles if no user is specified.
- Return type:
- id
-
Primary key: ID
- Type:
Type
- is_test
-
Is test. Indicates if this profile is used for unit testing purposes.
- Type:
Type
- llmclient_set
Reverse
ForeignKeyfromLLMClientAll LLMClients of this user profile (related name of
user_profile)- Type:
Type
- objects: SmarterBaseModelManager = <smarter.apps.account.models.user_profile.SmarterBaseModelManager object>
- pluginmeta_set
Reverse
ForeignKeyfromPluginMetaAll Plugins of this user profile (related name of
user_profile)- Type:
Type
- profile_image_url
-
Profile image url. URL to the user’s profile image, provided via oauth.
- Type:
Type
- prompt_set
Reverse
ForeignKeyfromPromptAll Chats of this user profile (related name of
user_profile)- Type:
Type
- provider_set
Reverse
ForeignKeyfromProviderAll Providers of this user profile (related name of
user_profile)- Type:
Type
- save(*args, **kwargs)[source]
Save the UserProfile instance and ensure account contacts are updated.
This method validates that both user and account are set, saves the profile, and, if newly created, adds the user to the account’s contact list. It also emits a signal for new user creation.
- Parameters:
args – Positional arguments passed to the parent save method.
kwargs – Keyword arguments passed to the parent save method.
Note
On first save, ensures at least one primary contact exists for the account.
Example usage:
profile.save()
- secrets
Reverse
ForeignKeyfromSecretAll secrets of this user profile (related name of
user_profile)- Type:
Type
- smarterauthtoken_set
Reverse
ForeignKeyfromSmarterAuthTokenAll API Keys of this user profile (related name of
user_profile)- Type:
Type
- tagged_items
Reverse
GenericRelationfromUserProfileAll + of this tagged item (related name of
tagged_items)- Type:
Type
- tags = <taggit.managers._TaggableManager object>
- updated_at
-
Updated at
Timestamp indicating when the model instance was last updated.
This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.
- Type:
Type
- user
ForeignKeytoUserUser (related name:
user_profile)- Type:
Type
- vectorestoremeta_set
Reverse
ForeignKeyfromVectorestoreMetaAll Vectorstore Metadata of this user profile (related name of
user_profile)- Type:
Type