user3731374
user3731374

Reputation: 201

Need helping with date format in Django

I have one trouble, in html file i'm need to use date field, and filed him date from django. Example my first field (correctly)

.datetimepicker({value:'{% now "Y-m-d H:i" %}',step:10});

In the next field, i must set mouth + 1, ho i can do this?

For example :

.datetimepicker({value:'{% now "Y-(m+1)-d H:i" %}',step:10});

Thanks.

Upvotes: 1

Views: 68

Answers (2)

Wael Ben Zid El Guebsi
Wael Ben Zid El Guebsi

Reputation: 2750

The django template system is meant to express presentation, not program logic this why you should do your logic at the view level

Upvotes: 1

David Dahan
David Dahan

Reputation: 11162

You can do it in the view (not in the template).

  • Create 2 variables (1 corresponding to now, 1 corresponding to now+1month)
  • Pass them to your template

In views.py

from datetime import datetime
def yourView(request):

    now_date = datetime.now()
    now_date_plus_1m = ... # I let you search how to to this :)

    return render_to_response('your_template.html',
        {
            'now_date': now_date,
            'now_date_plus_1m': now_date_plus_1m
        },
            RequestContext(request)
        )

In your template file:

.datetimepicker({value:'{{ now_date|date:"Y-m-d H:i" }}',step:10}); .datetimepicker({value:'{{ now_date_plus_1m|date:"Y-m-d H:i" }}',step:10});

Upvotes: 1

Related Questions