Suppose I have a model of Category, and it has been declared in admin.py.
There are two things that I want to do using Django template overriding.
- Add a button on the right near "Add Category +" which is visible only on the Category List page and takes me to another URL.
- Overriding URLs of Category object so that clicking on each individual category on the list takes to the respective URLs
# models.py
class Category(models.Model):
name = models.CharField(max_length=50, null=True, blank=False)
LANGUAGE_ENGLISH = 'en'
LANGUAGE_FRENCH = 'fr'
LANGUAGES = ((LANGUAGE_ENGLISH, 'English'),(LANGUAGE_FRENCH, 'French'),)
language = models.CharField(max_length=12, default=LANGUAGE_ENGLISH, choices=LANGUAGES, blank=False)
created_at = models.DateTimeField(auto_now_add=True)
# admin.py
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'language', 'created_at')
list_filter = ('created_at', 'language')
search_fields = ('name',)
date_hierarchy = 'created_at'
ordering = ['-created_at']
Category in the admin panel
Here, clicking on Lifestyle or Travel should take me to two external urls.