Y
Y
yuki2021-05-05 09:29:37
Django
yuki, 2021-05-05 09:29:37

Working with slug and pk in django?

I have 2 models (the first one is User, the standard one, the second one displays the user's resume)

class ResumesModel(models.Model):
    client_id = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    work_experience = models.IntegerField(verbose_name="Опыт работы")
    specialization = models.TextField(verbose_name="Специальность")
    desired_salary = models.IntegerField(verbose_name="Желаемая зарплата", blank=True)
    hard_skills = models.TextField(verbose_name="Ключевые навыки")
    about_you = models.TextField(verbose_name="О себе")
    native_language = models.TextField(verbose_name="Родной язык")
    foreign_language = models.TextField(verbose_name="Иностранный язык")

    def __str__(self):
        return str(self.client_id)


There is a class in views.py
class ResumesDetail(DetailView):
    model = ResumesModel
    template_name = "work/resumes/detail.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        # context["this_user"] = User.objects.get()
        return context


in urls
path('resumes/<slug:client_id>', views.ResumesDetail.as_view(), name="check_resume"),

How to correctly specify the slug for this class so that AttributeError does not pop up?

PS: client_id will return a string (eg: rst)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question