1

I have a Table with all my data, and when I try to edit one row I catch all data to a form, but the datepicker is showing ALWAYS one day less than the one entered. How can I solve this?. I read something about the DateTime from JS but I didn't find anything to solve my problem.

This is how the data is displayed in my table:

Data in Table

And in my form this is how it is received when I clicked the edit button (SubTotal, Calculated IVA and Total are in 0, ignore it, It is not relevant :D ):

Data in edit

Form.py

from datetime import datetime
from django.db.models.base import Model
from django.forms.fields import DecimalField
from django.forms import *
from core.erp.models import Sale
from tempus_dominus.widgets import DatePicker

class SaleForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    
    class Meta:
        model = Sale
        fields = '__all__'
        widgets = {
            'cli': Select(
                attrs={
                    'class': 'form-control select2'
                }
            ),
            'date_joined' : DatePicker(
                options={
                    'maxDate': datetime.now().strftime('%Y-%m-%d'),
                    'useCurrent': True,
                    'collapse': False
                },
                attrs={
                    'append': 'fas fa-calendar',
                    'icon_toggle': True,
                }
            ),
            'subtotal': NumberInput(
                attrs={
                    'class':'form-control',
                    'disabled' : True,
                    'autocomplete': 'off'
                }
            ),
            'iva': NumberInput(
                attrs={
                    'class':'form-control'
                }
            ),
            'total': NumberInput(
                attrs={
                    'class':'form-control',
                    'disabled': True,
                    'autocomplete': 'off'
                }
            )
        }
        exclude = ['user_creation', 'user_updated']

Template:

{% extends 'home.html' %} 
{% load widget_tweaks %}
{% load static %}
{% block head_list %}
  {{form.media}}
{% endblock %}
{% block content %}
<div class="col-lg-4">
          <div class="card card-secondary">
            <div class="card-header">
              <h3 class="card-title">Details of Bill</h3>
            </div>
            <div class="card-body">
              <div class="form-group">
                <label>Date Joined:</label>
                {{form.date_joined}}
              </div>
              <div class="form-group">
                <label>Client:</label>
                {{form.cli}}
              </div>
              <div class="form-group">
                <label>SubTotal:</label>
                {{form.subtotal}}
              </div>
              <div class="form-group">
                <label>IVA:</label>
                {{form.iva}}
              </div>
              <div class="form-group">
                <label>Calculated IVA:</label>
                <input type="text" class="form-control" readonly name="iva_calculated" value="0.00" autocomplete="off"/>
              </div>
              <div class="form-group">
                <label>Total:</label>
                {{form.total}}
              </div>
            </div>
          </div>
        </div>
{% endblock %}

Thank you very much in advance for your time. Greetings.

  • I ran into this same issue when I upgraded from 5.1.2.14 to 5.1.2.16. I looked into the code to try to understand what they changed exactly, but I haven't been able to figure out how to fix it so far, so I downgraded the version for the moment. My guess is it either has to do with some sort of moment.js formatting that they modified or with bumping the Tempus Dominus JS version significantly. – Mihai Chelaru Dec 09 '21 at 17:09

0 Answers0