V
V
Vladislav ...2021-04-06 10:13:08
Django
Vladislav ..., 2021-04-06 10:13:08

How to change links to third-party sites in the django admin panel?

Connoisseurs, please tell me how to make it possible to change links to social networks through django admin. networks such as vk insta ... in order not to constantly climb and change in html, but to enter the admin panel and change
the model, I created

class Social(models.Model):
title = models.CharField(max_length=255, verbose_name="Name of the social network ")
slug = models.SlugField(max_length=255, verbose_name="URL", unique=True)
img = models.ImageField(verbose_name='Network Logo', blank=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('social', kwargs={"slug": self.slug})
class Meta:
verbose_name = 'Social. Network'
verbose_name_plural = 'Social


class SocialAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}
admin.site.register(Social, SocialAdmin)

Only it issues a link that it generates.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-04-06
@akula993

This

slug = models.SlugField(max_length=255, verbose_name="URL", unique=True)

replace with something like this
social_url = models.URLField(blank=True, max_length=500)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question