diff --git a/django_project_base/rest/project.py b/django_project_base/rest/project.py index 5fa6d735..dae7a6e6 100644 --- a/django_project_base/rest/project.py +++ b/django_project_base/rest/project.py @@ -55,11 +55,13 @@ def __init__(self, *args, is_filter: bool = False, **kwds): self.fields.fields["owner"].display_form = DisplayMode.HIDDEN # logo = fields.FileField(display=DisplayMode.SUPPRESS, required=False) # todo: not implemented UI - owner = fields.AutoGeneratedField(display_table=DisplayMode.SUPPRESS, display_form=DisplayMode.HIDDEN) + + # we can remove the owner, because they're set at project creation and there will be a separate API for changing + # owner = fields.IntegerField(display_table=DisplayMode.SUPPRESS, display_form=DisplayMode.HIDDEN) class Meta: model = swapper.load_model("django_project_base", "Project") - exclude = ("logo",) # TODO we currently don't support logos well. see DPB #3 + exclude = ("logo", "owner") # TODO we currently don't support logos well. see DPB #3 layout = Layout(Row("name"), Row("slug"), Row("description")) @@ -68,15 +70,6 @@ class ProjectViewSet(DynamicModelMixin, ModelViewSet): permission_classes = (IsProjectOwnerOrReadOnly | CreateAny,) MODEL_FUNC_SETTING_NAME = "DJANGO_PROJECT_BASE_PROJECT_MODEL_AT_RUNTIME" - def new_object(self: ModelViewSet): - new_object = super().new_object() - if self.request and self.request.user and self.request.user.is_authenticated: - new_object.owner = getattr( - self.request.user, swapper.load_model("django_project_base", "Profile")._meta.model_name - ) - - return new_object - @staticmethod def _get_queryset_for_request(request): try: @@ -198,6 +191,13 @@ def set_args(name: str) -> None: return super().get_object() return super().get_object() + def perform_create(self, serializer): + serializer.save( + owner=self.request.user + if self.request and self.request.user and self.request.user.is_authenticated + else None + ) + def create(self, request, *args, **kwargs): create_response = super().create(request, *args, **kwargs) project = self.get_queryset().model.objects.get(slug=create_response.data["slug"])