Add custom field to admin fields

models.py

class Video(models.Model ):

    embedded_code = models.TextField(blank=False, null=False, default='')

This field represents youtube's embedded code.

In the form for editing an instance I'd like to have a link to a detail view where I would like to show the video. In other words, I don't want to shoow the video in the admin site, I'd like just to create a link. And it is not about list_display.

For that purpose in the model I could organise something like that:

def preview(self):
    href = reverse('vocabulary-videos:detail', kwargs={'pk': self.id})
    a = "<a href='{}'>Preview</a>".format(href)
    return mark_safe(a)

Is it possible to show this link in the edit form without substituting the template?

Back to Top