django rest not showing one of the endpoints in API root

Viewed 498

enter image description hereenter image description hereOne of the viewsets named 'wallet' is not showing in the main API page. I checked the routers registered in the urls, but I'm not finding the issue.

SiteWallet model:

class SiteWallet(models.Model):
    owner = models.OneToOneField(SiteUser, on_delete=models.CASCADE, related_name='SiteWallet')
    balance = models.DecimalField(max_digits=40, decimal_places=2, default=0 , blank=True, null=True)

    class Meta:
        verbose_name = 'Wallet'
        verbose_name_plural = 'Wallets'


    def __str__(self):
        return f"{self.owner} : {self.balance}$"

    def get_absolute_url(self):
        return reverse("Wallet_detail", kwargs={"pk": self.pk})

    def deposit(self, amount):
        self.balance += amount
        self.save()
        WalletTransaction.objects.create_deposit_transaction(self, amount)

    def withdraw(self, amount):
        if self.withdraw_valid(amount):
            self.balance -= amount
            self.save()
            WalletTransaction.objects.create_withdraw_transaction(self, amount)
        else:
            raise Exception("Not enough $")

    def withdraw_valid(self, amount):
        if self.balance >= amount:
            return True
        else:
            return False 

WalletSerializer:

class WalletSerializer(serializers.ModelSerializer):

    class Meta:
        model = SiteWallet
        fields = ['balance']

WalletViewSet:

class WalletViewSet(mixins.RetrieveModelMixin
                    ,viewsets.GenericViewSet):
"""endpoint for viewing the balance of wallet or charging it"""
    serializer_class = WalletSerializer
    permission_classes =[IsOwnerOrReadOnly]
    queryset = SiteWallet.objects.all()

    @action(detail=True, methods=['POST'])
    def charge_account(self, request):
        wallet = self.get_object()
        wallet.deposit(request.data['amount'])
        return Response(status=status.HTTP_200_OK)

    @action(detail=True, methods=['POST'])
    def withdraw(self, request):
        wallet = self.get_object()
        wallet.withdraw(request.data['amount'])
        return Response(status=status.HTTP_200_OK)

and the app's urls:

router = routers.DefaultRouter()
router.register(r"Users", SiteUserViewSet, basename="Site Users")
router.register(r"Wallet", WalletViewSet, basename="wallets")
router.register(r"Bank accounts", BankAccountViewSet, basename="bank account")
router.register(r"Wallet transaction", WalletTransactionViewSet, basename='wallet transaction')

urlpatterns =[
    path('login/', views.LoginView.as_view(), name='login'),
    path('logout/', views.LogoutView.as_view(), name='logout')
] + router.urls

I'm new to Django, if there's any part of the code that's badly written or needs refactoring, I would appreciate the tip.

0 Answers
Related