1

I am currently working on django. I created 4 classes in models.py, one of them is ReactionMeta class. This class has 62 columns, which defined as below:

class Reactionsmeta(models.Model):

id = models.ForeignKey('Reactions', db_column='id', primary_key=True, max_length=255, on_delete=models.CASCADE)
name = models.CharField(max_length=255, blank=True, null=True)
metabolite1 = models.ForeignKey('Metabolites', db_column='metabolite1', blank=True, null=True,
                                on_delete=models.CASCADE)
stoichiometry1 = models.CharField(max_length=255, blank=True, null=True)
metabolite2 = models.ForeignKey('Metabolites', db_column='metabolite2', blank=True, null=True,
                                on_delete=models.CASCADE, related_name='+')
stoichiometry2 = models.CharField(max_length=255, blank=True, null=True)
metabolite3 = models.ForeignKey('Metabolites', db_column='metabolite3', blank=True, null=True,
                               on_delete=models.CASCADE, related_name='+')
stoichiometry3 = models.CharField(max_length=255, blank=True, null=True)
metabolite4 = models.ForeignKey('Metabolites', db_column='metabolite4', blank=True, null=True,
                                on_delete=models.CASCADE, related_name='+')
#...

Some of the reactions, may have 6 metabolites, however, some of reactions may only have 2 metabolites and stoichiometries, which means there is no value of this reaction in metabolite3,4,5,6...columns and stoichiometry 3,4,5,6...columns.

In that case, how can I only display the Charfield with data while undisplay those Charfield with no value in django-admin?

HAOYANG MI
  • 151
  • 11

1 Answers1

0

So I think there is model design issue here. For my case i would have done this as follows

class ReactionMeta(models.Model):
  reaction = models.ForeignKey(Reaction, ..)
  name = models.CharField(..)
  data = models.ForeignKey(Data, ..)

Contructing the Data class to hold the Stoichiometry and Metabolite

class Data(models.Model):
  stoichiometry = models.CharField(..)
  metabolite = models.ForeignKey(..)
Emmanuel Mtali
  • 4,383
  • 3
  • 27
  • 53
  • Thank you for your suggestion. But I am still quite unclear about the data model, if you divide reactions and metabolite, stoichiometry into two different classes, then how come I know which reactions correspond to which metabolites and stoichiometry? – HAOYANG MI Mar 23 '18 at 19:36