Closed specialorange closed 6 years ago
After searching this repo I found this https://github.com/bennylope/django-organizations/blob/9058331e9ab8f1ce4b81b89cbc33211c113e4427/docs/reference/managers.rst
Is that what you were trying to do @specialorange ?
@specialorange had answered his question on the SO question linked above, but in a nutshell the original problem was missing the queryset method on the reverse relation manager.
My added comment on SO:
That's exactly it.
organizations_organization
is the named reverse relationship through theOrganizationUser
model (which is the linking or intermediate model) to theUser
model. That just returns theRelatedManager
and then from that manager you can call different query methods (e.g.all
,filter
, etc).
https://stackoverflow.com/questions/48852913/get-users-organizations-in-django-organizations
For the app django-organizations, how do you get a User's organization? From the docs it says
and in my code I can easily do :
but I am trying to work the other way now:
Notes
print loggedInPerson.organizations_organizationuser
->organizations.OrganizationUser.None
print loggedInPerson.organizations_organization
->organizations.Organization.None
print loggedInPerson.organizations_organization_set
-> errorsprint dir(loggedInPerson)
->['DoesNotExist', 'EMAIL_FIELD', 'Meta', 'MultipleObjectsReturned', 'REQUIRED_FIELDS', 'USERNAME_FIELD', 'class', 'delattr', 'dict', 'doc', 'eq', 'format', 'getattribute', 'hash', 'init', u'module', 'ne', 'new', 'reduce', '__reduce_ex', 'repr', 'setattr', 'setstate', 'sizeof', 'str', 'subclasshook', 'unicode', 'weakref__', '_check_column_name_clashes', '_check_field_name_clashes', '_check_fields', '_check_id_field', '_check_index_together', '_check_local_fields', '_check_long_column_names', '_check_m2m_through_same_relationship', '_check_managers', '_check_model', '_check_model_name_db_lookup_clashes', '_check_ordering', '_check_swappable', '_check_unique_together', '_do_insert', '_do_update', '_get_FIELD_display', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_get_unique_checks', '_meta', '_password', '_perform_date_checks', '_perform_unique_checks', '_save_parents', '_save_table', '_set_pk_val', '_state', 'check', 'check_password', 'clean', 'clean_fields', 'date_error_message', 'date_joined', 'delete', 'email', 'email_user', 'emailaddress_set', 'first_name', 'from_db', 'full_clean', 'get_all_permissions', 'get_deferred_fields', 'get_email_field_name', 'get_full_name', 'get_group_permissions', 'get_next_by_date_joined', 'get_previous_by_date_joined', 'get_session_auth_hash', 'get_short_name', 'get_username', 'groups', 'has_module_perms', 'has_perm', 'has_perms', 'has_usable_password', 'id', 'invoice_set', 'is_active', 'is_anonymous', 'is_authenticated', 'is_staff', 'is_superuser', 'job_set', 'last_login', 'last_name', 'logentry_set', 'natural_key', 'normalize_username', 'objects', 'organizations_organization', 'organizations_organizationuser', 'password', 'pk', 'pm_set', 'prepare_database_save', 'refresh_from_db', 'save', 'save_base', 'serializable_value', 'set_password', 'set_unusable_password', 'socialaccount_set', 'unique_error_message', 'user_permissions', 'username', 'username_validator', 'validate_unique']