python - How to get the name of an object through the template_tag? -


i want pass name of object through template tag got error:

'str' object has no attribute 'mymodelone_set' 

my models:

class mymodelone(models.model):     name = models.charfield(max_length=50)     show = models.foreignkey('mymodeltwo')      def __unicode__(self):         return self.title  class mymodeltwo(models.model):     title = models.charfield(max_length=50)     description = models.textfield(blank=true)      def __unicode__(self):         return self.name 

my template tag looks this:

in base.html:

{% load my_tags %}{% my_func obj%} 

in model_tag.py

register = template.library() @register.inclusion_tag('myapp/widget.html') def my_func(obj):     param1 = obj.mymodelone_set.all() return {} 

what doing wrong?

class mymodelone(models.model):     name = models.charfield(max_length=50)     show = models.foreignkey('mymodeltwo')      def __unicode__(self):         return self.name  class mymodeltwo(models.model):     title = models.charfield(max_length=50)     description = models.textfield(blank=true)      def __unicode__(self):         return self.title 

you had inverted self.name/self.title in wrong class, @ least that's looks me.


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -