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.
- Species (table 1) Columns: Species_id | specie_name
- Species_to_states (table 2) Columns: Species_id | State_id
- States (table 3) Columns: States_id, State_name
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?