date display problem?

21 views
Skip to first unread message

Navnath Gadakh

unread,
Sep 18, 2012, 10:34:39 PM9/18/12
to django...@googlegroups.com
i have post date variable to view? but when i retrieve date from database . not displaying on browser

Lachlan Musicman

unread,
Sep 18, 2012, 10:46:42 PM9/18/12
to django...@googlegroups.com
On Wed, Sep 19, 2012 at 2:34 PM, Navnath Gadakh <navnat...@gmail.com> wrote:
> i have post date variable to view? but when i retrieve date from database .
> not displaying on browser

We need more information than that - do you mean it's not displaying
in a form, in a regular template or in the admin pages?

And how are you referencing it? Send us the relevant code to look at?

Cheers
L.

>
> --
> 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/-/t7LK3gY0Ib0J.
> 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.



--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

Navnath Gadakh

unread,
Sep 18, 2012, 11:51:20 PM9/18/12
to django...@googlegroups.com
model
   class Offer(models.Model):
    product_id = models.ForeignKey(Product)
    merchant_id = models.ForeignKey(Merchant)
    offer_id = models.AutoField(primary_key=True)
    description = models.CharField(max_length=100,null=False)#Not NULL
    effective_date = models.DateField()
    expiration_date = models.DateField()




view.py
                    HTML = HTML + "<div>"
                    HTML = HTML + "<b>Offer Description : </b>"+offer.description+"<br>"   
                    HTML = HTML + "<b>Coupon Number :  </b>"+coupon_no.coupon_detail+"<br>"
                    HTML = HTML + "<b>Effective Date : </b>"+str(offer.effective_date)+"<br>"
                    HTML = HTML + "<b>Expiration Date : </b>"+str(offer.expiration_date)+"<br>"
                    HTML = HTML + "<hr>"                               
                    HTML = HTML + "</div>"

at the time of create offer i print variable for expiration and effective date in view it worked fine.
but in temlate it did't other fields displays.
effective date and expiration date not displaying on browser..

Lachlan Musicman

unread,
Sep 18, 2012, 11:57:39 PM9/18/12
to django...@googlegroups.com
On Wed, Sep 19, 2012 at 3:51 PM, Navnath Gadakh
<navnat...@gmail.com> wrote:
> model
> class Offer(models.Model):
> effective_date = models.DateField()
> expiration_date = models.DateField()

Nothing wrong here

> view.py
> HTML = HTML + "<div>"
> HTML = HTML + "<b>Offer Description :
> </b>"+offer.description+"<br>"
> HTML = HTML + "<b>Coupon Number :
> </b>"+coupon_no.coupon_detail+"<br>"
> HTML = HTML + "<b>Effective Date :
> </b>"+str(offer.effective_date)+"<br>"
> HTML = HTML + "<b>Expiration Date :
> </b>"+str(offer.expiration_date)+"<br>"
> HTML = HTML + "<hr>"
> HTML = HTML + "</div>"
>
> at the time of create offer i print variable for expiration and effective
> date in view it worked fine.
> but in temlate it did't other fields displays.
> effective date and expiration date not displaying on browser..


My django isn't good enough to quiet understand your view, but since
you have the offer object there in the view, why don't you pass it to
the template via

render_to_response('/path/to/template.html',{'offer':offer})

And then in your template path/to/template.html

you just need to use the variable

{{ offer.effective_date }}

for instance?

cheers
L.

Stephen Anto

unread,
Sep 19, 2012, 2:49:34 AM9/19/12
to django...@googlegroups.com
Hi,

How to fetch data, are you fetching single row or multiple rows?

offers = Offer.objects.all()

for offer in offers:
     print offer.effective_date

If you use like above it will work. pls check your code. Thank you for visiting For Django

--
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/-/cTFKSlnEUEsJ.

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.



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Navnath Gadakh

unread,
Sep 19, 2012, 6:19:13 AM9/19/12
to django...@googlegroups.com
i am fetching multiple rows?
  i have already used
  for offer in offers:
      print offer.effective _date
but didnt work.my code is
 my_offers = Offer.objects.filter(offer_id=coupon.offer_id_id,is_active=True) 
                for offer in my_offers:
                    print offer.effective_date

                    HTML = HTML + "<div>"
                    HTML = HTML + "<b>Offer Description : </b>"+offer.description+"<br>"   
                    HTML = HTML + "<b>Coupon Number :  </b>"+coupon_no.coupon_detail+"<br>"
                    HTML = HTML + "<b>Effective Date : </b>"+str(offer.effective_date)+"<br>"
                    HTML = HTML + "<b>Expiration Date : </b>"+str(offer.expiration_date)+"<br>"
                    HTML = HTML + "<b>Experience Points : </b>"+str(offer.experience_points)+"<br>"      
                    HTML = HTML + "<b>Discount : </b>"+str(offer.discount)+"<br>"      
                    #HTML = HTML + "<b>Offer Date : </b>"+str(coupon_no.date_of_offer)+"<br>"

Lachlan Musicman

unread,
Sep 19, 2012, 4:26:40 PM9/19/12
to django...@googlegroups.com
I'm still confused about the HTML string you have here, but anyway,
have you tried either checking that
Offer.objects.filter(offer_id=coupon.offer_id_id,is_active=True) is
returning something in the shell or adding a __unicode__(self) and
then

Offer.objects.filter(offer_id=coupon.offer_id_id,is_active=True)
for offer in my_offers:
print offer

to check that your filter is working?

cheers
L.
Reply all
Reply to author
Forward
0 new messages