Any help or instruction will be appreciated..

Hello every, I am a newbie and trying to make a project, please see the code I have uploaded and instruct me what can i or what can’t i do this in this project…
Requirements:

  1. Implement token-based authentication using Django REST Framework’s built-in authentication classes. Only authenticated users should be able to perform CRUD operations.

  2. Users should be able to register an account, login, and retrieve their authentication token. • Each artist object should have the following fields:

  3. Artist Table :black_small_square: Name :black_small_square: User Instance (Foreign Key) :black_small_square: Work (ManyToManyField)

  4. Work Table :black_small_square: Link :black_small_square: Work Type • Youtube • Instagram • Other ❖ Important :black_small_square: After each ‘Registration’ for a new user :black_small_square: Make sure a new Artist object is created using signals • Rest API ◦ Integrate API endpoints for the following operations: :black_small_square: Retrieving a list of all works :black_small_square: Create a new work :black_small_square: Integrate Filtering with Work Type :black_small_square: Integrate Search with Artist name

modles.py

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Work(models.Model):
    link = models.URLField()
    work_type = models.CharField(max_length=10, choices = [('YT', 'Youtube'), ('IG', 'Instagram'), ('Other', 'Other')])

    def __str__(self):
        return self.work_type
    
class Artist_t(models.Model):
    name = models.CharField(max_length = 50)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    work = models.ManyToManyField(Work)

    def __str__(self):
        return self.name

views.py

from django.shortcuts import render, redirect
from .forms import UserReg
from rest_framework.authtoken.models import Token
from django.contrib.auth.decorators import login_required

# Create your views here.
def register(request):
    if request.method == 'POST':
        form = UserReg(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')
    form = UserReg()
    return render(request, 'register.html', {'form' : form})

@login_required
def home(request):
    return render(request, 'home.html')

def get_token(request):
    tok, create = Token.objects.get_or_create(user=request.user)
    return render(request, 'home.html', {'tok':tok})

serializers.py

from Artist.models import Artist_t, Work
from rest_framework import serializers

class WorkSerializer(serializers.ModelSerializer):
    class Meta:
        model = Work
        fields = '__all__'

class ArtistSerializer(serializers.ModelSerializer):
    # user = serializers.StringRelatedField(many=False)
    # user = serializers.SlugRelatedField(
    #     many=False,
    #     read_only=True,
    #     slug_field='username'
    #  )
    work = WorkSerializer(many=True)
    class Meta:
        model = Artist_t
        fields = ['name', 'user', 'work']

signals.py

from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from Artist.models import Artist_t
from rest_framework.authtoken.models import Token

@receiver(post_save, sender=User)
def create_Artist(sender, instance=None, created=False, **kwargs):
    if created:
        Artist_t.objects.create(name=instance.username, user=instance)

@receiver(post_save, sender=User)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)

api/views.py


from .serializers import ArtistSerializer, WorkSerializer
from Artist.models import Artist_t, Work
from rest_framework import viewsets
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAuthenticated
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter

class ArtSet(viewsets.ModelViewSet):
    queryset = Artist_t.objects.all()
    serializer_class = ArtistSerializer
    # authentication_classes = [TokenAuthentication]
    # permission_classes = [IsAuthenticatedOrReadOnly]
    filter_backends = [DjangoFilterBackend, SearchFilter]
    # filter_backends = [SearchFilter]
    filterset_fields = ['work']
    search_fields = ['name']

class WorkSet(viewsets.ModelViewSet):
    queryset = Work.objects.all()
    serializer_class = WorkSerializer
    # authentication_classes = [TokenAuthentication]
    # permission_classes = [IsAuthenticatedOrReadOnly]

Welcome @Dadduu2001 !

You’re going to need to be more specific about the type of assistance being requested here.

What is your question, or issue that you’re trying to resolve?

Thanks for your reply. As you can see in readme file that i have to make an api using token based authentication. So I want to confirm that I have made the api using right method or sequence. It will be very helpful if you go through the api and instruct me that what i have done is right or i can do this in different manner.

You are more likely going to find someone willing to assist you if you clearly identify the issue here, along with the specific code that you think may be improved. Your post is less likely going to draw interest if you’re expecting people to go digging through a repo.

Thanks for your advice , I have updated my post , now please assist me :blush: