You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now we use a brute force approach that defines which field on user and joined fields from other models need to be tackled when transferring a user. For a more solid approach, use Django's lookup to find and handle these fields.
The downside with the current approach is that the transfer setup up could break as we add in new models with joins to user and require more code maintenance.
I (Rachid) tried using a related field lookup when working on #2579 which was partly successful. The lookup (based on Dave's work on the 'join' alert on contacts) works, but the field update fails:
try:
related_objects = []
for related_field in selected_user._meta.get_fields():
if related_field.is_relation and related_field.auto_created:
related_manager = getattr(selected_user, related_field.get_accessor_name(), None)
if related_manager:
if hasattr(related_manager, "get_queryset"):
queryset = related_manager.get_queryset()
else:
queryset = [related_manager]
for obj in queryset:
field_name = related_field.field.name
if related_field.many_to_one or related_field.one_to_one:
setattr(obj, field_name, current_user)
elif related_field.many_to_many:
print(f'many to many handling')
if selected_user in related_manager.all():
related_manager.remove(selected_user)
related_manager.add(current_user)
obj.save()
Links to other issues
No response
The text was updated successfully, but these errors were encountered:
Added ACs and some other details, marking this as ready, due to the nature of this being a code maintenance issue, would like it to be done anywhere within the next 3 sprints.
Issue description
Right now we use a brute force approach that defines which field on user and joined fields from other models need to be tackled when transferring a user. For a more solid approach, use Django's lookup to find and handle these fields.
The downside with the current approach is that the transfer setup up could break as we add in new models with joins to user and require more code maintenance.
Acceptance criteria
Additional context
I (Rachid) tried using a related field lookup when working on #2579 which was partly successful. The lookup (based on Dave's work on the 'join' alert on contacts) works, but the field update fails:
`def post(self, request, user_id):
current_user = get_object_or_404(User, pk=user_id)
selected_user_id = request.POST.get('selected_user')
selected_user = get_object_or_404(User, pk=selected_user_id)
Links to other issues
No response
The text was updated successfully, but these errors were encountered: