1

I have Views.py

class newChartView(TemplateView):
    template_name = "new_report_view.html"

    def get_context_data(self, **kwargs):
        context = super(newChartView, self).get_context_data(**kwargs)
        context['count'] = smslogger.objects.all()
        return context

and new_report_view.html as

{% for x in count %}
{{ x.count }}
{% endfor %}

and it show error

'module' object has no attribute 'objects'

smsloggger

model

class Log(models.Model):
   date= models.DateField()
   count=models.CharField(max_length=100)
   class Meta:
        verbose_name_plural = "SMS Log"

   def __unicode__(self):
        return self.date,self.count

I want to have the data from smslogger app. How can I acheive it through TemplateView subclass

Laxmi Kadariya
  • 1,103
  • 1
  • 14
  • 34

1 Answers1

5

Could you let us know what smslogger.py contains ?

I think you might be need to do something like this.

from smslogger import YourModel

class newChartView(TemplateView):
    template_name = "new_report_view.html"

    def get_context_data(self, **kwargs):
        context = super(newChartView, self).get_context_data(**kwargs)
        context['count'] = YourModel.objects.all()
        return context
JRajan
  • 672
  • 4
  • 19