Does it make sense to define get_create_url(), get_update_url() and get_delete_url() for an object?

Hi there,

Inspired in this stackoverflow question I would like to ask you what do you think of creating get_absolute_url(), get_create_url(), get_update_url() and get_delete_url() for an object in the model?

Something like this:

class Post(models.Model):
    # fields and methods for the Post model...

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

    def get_create_url(self):
        return reverse('post_create')

    def get_update_url(self):
        return reverse('post_update', kwargs={"pk": self.pk})

    def get_delete_url(self):
        return reverse('post_delete', kwargs={"pk": self.pk})

Thanks!

1 Like