I am currently trying to have the item page in the django admin (ie, /admin/dictionary/word/153/change) show less, I am just unsure how to do this.
Given any random word can have say 10000 upvotes, it takes a while to actually make it to the page when it loads. So don't want it to show the votes?
This is my admin.py and my models.
from django.contrib import admin
from diccionario.models import Palabra, Tag
from django.utils.safestring import mark_safe
class TagInline(admin.TabularInline):
model = Tag
def has_change_permission(self, request, obj=None):
return False
def has_add_permission(self, request, obj=None):
return False
class PalabraAdmin(admin.ModelAdmin):
list_display = (
'nombre',
'get_post_action',
'definicion',
'ejemplo',
'gramatica',
'get_sinonimos',
'get_antonimos',
'pais',
'creado',
'get_user_username',
'aprobada',
'anonimo'
)
list_filter = (
'creado',
)
inlines = [TagInline]
def get_sinonimos(self, obj):
return ', '.join([item.nombre for item in obj.tag_set.filter(tag_type='Sinónimo')])
def get_antonimos(self, obj):
return ', '.join([item.nombre for item in obj.tag_set.filter(tag_type='Antónimo')])
def get_user_username(self, obj):
if obj.user:
return obj.user.username if obj.user.username else obj.user.email
def get_post_action(self, obj):
return mark_safe('<a class="btn btn-primary" href="/api/admin/aprobar/%s">Aprove</a>'
'<div style="margin: 5px 0"></div>'
'<a class="btn btn-danger" href="/api/admin/borrar/%s">Borrar</a>'
'<div style="margin: 5px 0"></div>' % (
obj.id,
obj.id,
))
get_sinonimos.short_description = 'Sinónimos'
get_antonimos.short_description = 'Antónimos'
get_user_username.short_description = 'username'
get_post_action.short_description = 'action'
admin.site.register(Palabra, PalabraAdmin)
And here is the models.py
import re
from django.db import models
from accounts.models import CustomUser
class IpAddress(models.Model):
creado = models.DateTimeField(auto_now_add=True)
ip_address = models.GenericIPAddressField(unique=True)
class Palabra(models.Model):
nombre = models.TextField(max_length=250)
definicion = models.CharField(max_length=1000, unique=True)
ejemplo = models.CharField(max_length=250)
creado = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, null=True, blank=True)
anonimo = models.BooleanField(default=True)
aprobada = models.BooleanField(default=False)
userUpVotes = models.ManyToManyField(IpAddress, blank=True, related_name='threadUpVotes')
userDownVotes = models.ManyToManyField(IpAddress, blank=True, related_name='threadDownVotes')
gramatica = models.CharField(max_length=250, null=True, blank=True)
pais = models.CharField(max_length=250, null=True, blank=True)
Basically I want the userUpvotes and userDownvotes to now show on the object page in the admin of the word. But not sure where I go about editing that template? Or is it in the admin.py?
Or take out the sections showing all the IpAddressObjects in this image
