Reputation:
Please could tell me why I can't modify my model in the admin panel of Django ?
models.py :
from django.db import models
# Create your models here.
class Games(models.Model):
guid = models.CharField(max_length=100, unique=True, null=False, verbose_name="GUID")
title = models.CharField(max_length=100, null=False, verbose_name="Titre")
logo = models.CharField(max_length=100, null=True, blank=True, verbose_name="Logo")
date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Date de création")
update = models.DateTimeField(auto_now=True, verbose_name="Dernière modification")
admin.py
from django.contrib import admin
from .models import Games
# Register your models here.
class GamesAdmin(admin.ModelAdmin):
list_display = ('logo', 'title', 'guid', 'date', 'update')
list_filter = ('title', 'guid')
date_hierarchy = 'update'
ordering = ('date', )
search_field = ('guid', 'title')
admin.site.register(Games, GamesAdmin)
When I'm going to the admin panel, I see all the field of my model, I can also add a new field. But when I want to edit the field, there is no link clickable...
Thanks !
Upvotes: 2
Views: 1874
Reputation: 308939
By default, the first column should be clickable and take you to the view to change the object. Even if the column is empty, Django will add a clickable non-breaking space (
), although you might not spot it until you hover over it and the cursor changes.
You can set link_display_links
and include a field that is not empty.
class GamesAdmin(admin.ModelAdmin):
list_display = ('logo', 'title', 'guid', 'date', 'update')
list_display_links = ('title',)
Alternatively, you could reorder list_display
so that the first column is not empty.
To make all columns clickable, you would set list_display_links = list_display
.
Upvotes: 2
Reputation: 187
Just swap the places of 'logo' and 'title' or 'logo' with any other non-empty column.
list_display = ('logo', 'title', 'guid', 'date', 'update')
Upvotes: 5