diff --git a/esim-cloud-backend/libAPI/admin.py b/esim-cloud-backend/libAPI/admin.py index 2fe449a3a..d1dbdd7f6 100644 --- a/esim-cloud-backend/libAPI/admin.py +++ b/esim-cloud-backend/libAPI/admin.py @@ -52,9 +52,9 @@ def toggle_default(self, request, obj, parent_obj=None): ) library_set.save() messages.info(request, mark_safe( - f"Library {obj.library_name} moved to '\ - ''\ - '{library_set.name}.")) + f"Library {obj.library_name} moved to \ + \ + {library_set.name}.")) obj.library_set = library_set obj.save() @@ -75,7 +75,7 @@ def get_form(self, request, obj=None, **kwargs): def save_model(self, request, obj, form, change): # For new library set instance User = get_user_model() - user = User.objects.get(id=request.POST.get('user')) + user = User.objects.get(id=request.user.id) if obj.pk is None: obj = LibrarySet( user=user, @@ -86,6 +86,8 @@ def save_model(self, request, obj, form, change): # If the library set is being changed else: + user = (LibrarySet.objects.get(id=obj.pk)).user + obj.user = user obj.save() files = request.FILES.getlist('files') diff --git a/esim-cloud-backend/libAPI/forms.py b/esim-cloud-backend/libAPI/forms.py index 7fe0e29f9..00151cab9 100644 --- a/esim-cloud-backend/libAPI/forms.py +++ b/esim-cloud-backend/libAPI/forms.py @@ -13,6 +13,7 @@ def __init__(self, *args, **kwargs): instance = getattr(self, 'instance', None) if instance and instance.pk: self.fields['user'].widget.attrs['disabled'] = True + self.fields['user'].required = False self.fields['name'].widget.attrs['readonly'] = True class Meta: