_set.all in template should be simple, wood and trees maybe?

297 views
Skip to first unread message

MikeKJ

unread,
Nov 29, 2012, 9:06:53 AM11/29/12
to django...@googlegroups.com
I dont get the hot_topic_set.all from the newsletter instance x and I really don't see why can anyone else please?

model:
class NewsLetter(models.Model):
    title = models.CharField(max_length=200)
    text = models.TextField(null=True, blank=True)
    document = models.FileField(upload_to="newsletters/", null=True, blank=True)
    priority = models.IntegerField(default=50)

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/newsletters/"

    class Meta:
        ordering = ('priority',)

class Hot_Topic(models.Model):
    newsletter = models.ForeignKey(NewsLetter, related_name="letter_set")
    topic = models.CharField(max_length=100)
    priority = models.IntegerField(default=50)

    class Meta:
        verbose_name_plural = "Hot Topics"
        ordering = ('priority',)

view
def index(request):
    list = NewsLetter.objects,all()
    return render_to_response('newsletter/index.html', {''list': list,}, context_instance=RequestContext(request))

template:
{% for x in list %}
    {% if x.text %}
        .........
    {% else %}
        {% for t in x.hot_topic_set.all %}
            {{ t.topic }}
        {% endfor %}
   {% endif %}
{% endfor %}

I dont get the hot_topic_set.all from the newsletter instance x and I really don't see why can anyone else please?
  

carlos

unread,
Nov 29, 2012, 10:10:05 AM11/29/12
to django...@googlegroups.com
are you sure you have data that show?



  

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/LWo5COXB5-wJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

MikeKJ

unread,
Nov 29, 2012, 10:17:09 AM11/29/12
to django...@googlegroups.com
Good question, I have attempted to shell the problem out and no I dont get a dataset returned, I should do as NewsLetter is foreignkeyed to Hot_Topic and Hot_Topic_Inline is an inlines to NewsLetterAdmin so the models are definately related

carlos

unread,
Nov 29, 2012, 10:32:44 AM11/29/12
to django...@googlegroups.com
{% for x in list %}
     {{x.text}} <br> 
    {% for t in x.hot_topic_set.all %}
        {{ t.topic }} <br>
    {% endfor %}
    
{% endfor %}

try only erase the if tag work for me !!

On Thu, Nov 29, 2012 at 9:17 AM, MikeKJ <mike....@paston.co.uk> wrote:
Good question, I have attempted to shell the problem out and no I dont get a dataset returned, I should do as NewsLetter is foreignkeyed to Hot_Topic and Hot_Topic_Inline is an inlines to NewsLetterAdmin so the models are definately related

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9Dd5Ea1WMYwJ.

Bill Freeman

unread,
Nov 29, 2012, 10:48:41 AM11/29/12
to django...@googlegroups.com
You have specified related_name to the foreign key in HotTopic.  Try either taking that out, or using newsletter_instance.letter_set.all .

MikeKJ

unread,
Nov 29, 2012, 11:03:36 AM11/29/12
to django...@googlegroups.com
Perfect, thanks
Reply all
Reply to author
Forward
0 new messages