Using User Model outside of Django Web App with Django Rest Framework

I have a model called File in my Django Web App. At the moment it looks like this:

from django.db import models
from django.conf import settings

class File(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             related_name='files_owned',
                             on_delete=models.CASCADE,
                             default)

    file_name = models.CharField(max_length=20, default=None, blank=False, null=False)
    file_path = models.CharField(max_length = 50, default=None, blank=False, null=False)

I have an endpoint using the Django REST Framework, where I can get a list of all Files and create a new File. Currently the endpoint looks like this:

Files Endpoint

The POST request at the moment only allows for file_path and file_name to be entered, I want to be able to enter a user ID or a User model, but the script that uses the endpoint is outside of the django web app so cannot access the User model.

Here is my serializer. The user_id field is what is in the DB as a field

class FileSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = File
        fields = ('id', 'user_id', 'file_name', 'file_path')

What would be the best solution for this, while maintaining a foreign key relationship in my DB

Back to Top