I'm programming an app for the edXproyect using Django and I need to retrieve some information from auth_user table and I don't know how to do it. I have this:
models.py
from django.db import models
from django.contrib.auth.models import User
class Recomendacion(models.Model):
usuario = models.ForeignKey(User, db_column='username', primary_key=True)
recurso = models.CharField(max_length=255, db_column='next_module')
def __str__(self):
return u'%s' % (self.usuario.username)
admin.py
from django.contrib import admin
from recomendador.models import Recomendacion
class RecomendacionAdmin(admin.ModelAdmin):
fields = ['usuario', 'recurso']
list_display = ['usuario', 'recurso']
admin.site.register(Recomendacion, RecomendacionAdmin)
But I would like to display something like:
list_display = ['id', 'usuario', 'full_name', 'recurso']
So I have to retrieve the id
and full_name
from the auth_table
with the username
field. I have tried adding classmethods in Recomendador like:
def get_id(self):
return self.usuario.id
and now I want to call them from the RecomendacionAdmin
class so I can list the id
and full_name
fields too but I don't know how to do it. I have googled it but I only get exceptions and errors with the solutions I find. Can anyone help me with this? I'm new to python...