python - Django models foreign key in unicode outpu -


i have 1 many relationship model year , has foreign key model compound. trying django admin widget include class name can pulled drop down /autocomplete.

i have

def __unicode__(self):         return u'(%s) %d' % (self.compound.compound_name, self.year) 

but doesn't return compound name expect attribute in model compound.

class year(models.model):     compound = models.foreignkey('compound', blank=false, null=false)     year = models.positivesmallintegerfield(blank=true, null=true)      def __unicode__(self):         return u'(%s) %d' % (self.compound.compound_name, self.year)  class compound(models.model):     dif_id = models.charfield(max_length=50, blank=true, default='unknown')     type = models.charfield(max_length=50, blank=true, default='sm')     compound_name = models.charfield(max_length=100, blank=true, default='unknown')     phase = models.positivesmallintegerfield(db_index=true, default=0)  def __unicode__(self):         return u'%s %s %s %d' % (self.dif_id,self,type,self.compound_name,self.phase )     class meta:         verbose_name_plural = 'compounds' 

any idea how should compound_name? , also, looking improve checking if compound_name unknown display dif_id .

thanks


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -