Reputation: 109
I've been struggling with a situation in Django/Mysql.
There is this column in a table that has a primary key and foreign key at the same time. This column has a one to many relation with an intermediary table.
It's a list of states linked to plant species. Some species can be found in more than one state.
Models.py (code below)
class Listaflor(models.Model):
especie = models.OneToOneField(Flora2Estado, models.DO_NOTHING, primary_key=True)
class Flora2Estado(models.Model):
estado = models.OneToOneField(Estados, models.DO_NOTHING, primary_key=True)
especie = models.ForeignKey('Listaflor', models.DO_NOTHING)
class Estados(models.Model):
estado_id = models.AutoField(primary_key=True)
estado_nome = models.CharField(max_length=100, blank=True, null=True)
nome_abbr = models.CharField(max_length=2, blank=True, null=True)
criadoem = models.DateTimeField(db_column='criadoEm') # Field name made lowercase.
class Meta:
managed = False
db_table = 'estados'
verbose_name = "Estados"
verbose_name_plural = "Estado"
def str(self):
return self.estado_nome+ " (" + self.nome_abbr+")"
The point is that only one object is being displayin django admin (check the image below). So i would like to show multiple fields within a row.
Can someone help me with that?
Thank you so much
class floAdmin(admin.ModelAdmin):
list_display = ('especie','familia','regiaopred','emailautor','aprovado','datacriado','especie_0')
fieldsets = (
('Editar:', {
'fields': (
'especie','familia','regiaopred','emailautor','aprovado','datacriado','especie_0'
#'pes_vinculo_tipo'
)
}),
)
Just like the image below, I want to display "Miami, Ny and Maine", for example, in only one row in django admin. Is that possible?
Upvotes: 3
Views: 2439
Reputation: 29
If I true understood) because I had the same problem. This helped me:
fieldsets=(
("My Group",{"fields": (tuple(['field1','field1']),),}),
)
Wrap those fields on their own tuple. There was answer Django admin display multiple fields on the same line
Upvotes: 1
Reputation: 886
I don't understand what info you want to get in a cell, but want to suggest you to use the next approach:
class floAdmin(admin.ModelAdmin):
list_display = ('especie', 'familia', 'regiaopred', 'emailautor', 'aprovado', 'datacriado', 'especie_0', 'custom_field', )
fieldsets = (
('Editar:', {
'fields': ('especie', 'familia', 'regiaopred', 'emailautor', 'aprovado', 'datacriado', 'especie_0', 'custom_field', )
}),
)
def custom_field(self, obj):
data_list_to_show = [] # get data based on obj
return data_list_to_show
Upvotes: 1