is possible to use uuid for id and slug for url?

I used uuid for id, but now i want to turn into slug in one of my views


class Club(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    slug = models.SlugField(null=True)

urlpatterns = [path("slug:slug", RankClubView.as_view(), name="ranking_club"),]

View (RankView inherited from TemplateView):

class RankClubView(RankView):
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        club = Club.objects.filter(pk=self.kwargs["pk"]).first()
        context["club"] = club
        context["all_players"] = context["all_players"].filter(club=club)
        return context

<a href="{% url 'Ranking:ranking_club' %}">{{}}</a>

This is giving me this error:

NoReverseMatch at /

Reverse for ‘ranking_club’ with arguments ‘(‘cdplaflorida’,)’ not found. 1 pattern(s) tried: [‘ranking/slug:slug\Z’]

So, how can i keep the uuid for the id and use slug for url?


That’s not a properly formatted path statement.

The “variable:converter” specification is enclosed by < >. See the docs and examples at URL dispatcher | Django documentation | Django.

Hi KenWhitesell, thanks for the help, that was a copy/paste mistake by me. The mistake was in the view:

club = Club.objects.filter(pk=self.kwargs["pk"]).first()

intead of

club = Club.objects.filter(slug=self.kwargs["slug"]).first()

Thanks !