Wednesday, May 25, 2016

Re: overriding date format

On Wed, May 25, 2016 at 3:58 AM, James Schneider
<jrschneider83@gmail.com> wrote:
>
> On May 24, 2016 3:32 PM, "Larry Martell" <larry.martell@gmail.com> wrote:
>>
>> I have 1 page in my app where I want to override the app's date
>> format. I tried assigning to settings.DATE_FORMAT in the view but that
>
> Django warns that settings should not be modified at runtime, which is
> probably why it had no effect:
>
> https://docs.djangoproject.com/en/1.9/topics/settings/#altering-settings-at-runtime
>
>> had no effect. I know I can format the date in the template, but
>> without making a lot of changes, I don't know what fields are dates. I
>> thought perhaps the date filter would just pass through non-dates
>> unchanged, but that's not what it did.
>>
>> How can I override the date format just for 1 view or how can I tell
>> in the template if a field is date or not?
>
> I would use one of a couple options:
>
> - Examine the data within the view, and modify those fields with the correct
> date format before passing your data off to the context to be rendered. At
> that point you still have the full complement of Python tools at your
> disposal without the drag of the template processor nuances and slower
> processing time.

Yes, that is what I ended up doing.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY6kxvCXvNmXqUpC10FF0hdcycdk3eLYcVLnP4yd6Cn9dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment