Import model class attributes from another app

0

Good afternoon guys, I'm good, a doubt! I'm using 2 Apps in django admin

App1 = Registration

App2 = Controllers control

I imported the app1 model, the "Person" class into the "Scholarship" class, but it only takes the "Name" attribute and I can only list the name in Display_list in admin.py app2.

Can I list the other attributes of the "Person" class, such as address or child_date in the display_list in my App2 (Player Control) ?? and how do I do that?

Who can help me, I thank you from now on!

registrations / models.py

class Pessoa(models.Model):


    CPF = models.CharField(primary_key = True, max_length = 11)
    Nome = models.CharField(max_length= 45)
    Data_nascimento = models.DateField()
    Endereço = models.CharField(max_length=45)

    def __str__(self):
        return "%s" % (self.Nome)

players control / models.py

from django.db import models
from ..cadastros.models import Pessoa

  class Bolsista(models.Model):


     pessoa = models.ForeignKey("cadastros.Pessoa")  


     def __unicode__(self):
         return 'Bolsista:' + self.pessoa

Players control / admin.py

from django.contrib import admin
from gestaobolsistas.controledebolsistas.models import Bolsista

    class BolsistaAdmin(admin.ModelAdmin):

        model=Bolsista
        list_display = ['pessoa']
        search_fields = ['pessoa']
    admin.site.register(Bolsista, BolsistaAdmin)
    
asked by anonymous 27.01.2017 / 05:57

1 answer

0

A very simple way for you to do this is to define a method in your BolsistaAdmin to return this information. Then it could look like this:

from django.contrib import admin
from gestaobolsistas.controledebolsistas.models import Bolsista

class BolsistaAdmin(admin.ModelAdmin):

    model = Bolsista
    list_display = ('pessoa', 'get_pessoa_cpf',)
    search_fields = ('pessoa',)

    def get_pessoa_cpf(self, obj):
        return obj.pessoa.CPF
    get_pessoa_cpf.short_description = 'CPF'

admin.site.register(Bolsista, BolsistaAdmin)
    
27.01.2017 / 14:08