Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, thanks for all your answers. None of them, as is, was a good solution for my problem, but, for your defense, I should add that I didn't give all the requirements. But each one help me think about my problem and some of your ideas are part of my final solution.</p> <p>So my final solution, on the DB side, is to use a <em>varchar</em> field (limited to 10 chars) and storing the date in it, as a string, in the ISO format (YYYY-MM-DD) with <em>00</em> for month and day when there's no month and/or day (like a <em>date</em> field in MySQL). This way, this field can work with any databases, the data can be read, understand and edited directly and easily by a human using a simple client (like mysql client, phpmyadmin, etc.). That was a requirement. It can also be exported to Excel/CSV without any conversion, etc. The disadvantage is that the format is not enforce (except in Django). Someone could write <em>'not a date'</em> or do a mistake in the format and the DB will accept it (if you have an idea about this problem...).</p> <p>This way it's also possible to do all of the <em>special</em> queries of a <em>date</em> field relatively easily. For queries with WHERE: &lt;, >, &lt;=, >= and = work directly. The IN and BETWEEN queries work directly also. For querying by day or month you just have to do it with EXTRACT (DAY|MONTH ...). Ordering work also directly. So I think it covers all the query needs and with mostly no complication.</p> <p>On the Django side, I did 2 things. First, I have created a <code>PartialDate</code> object that look mostly like <code>datetime.date</code> but supporting date without month and/or day. Inside this object I use a datetime.datetime object to keep the date. I'm using the hours and minutes as flag that tell if the month and day are valid when they are set to 1. It's the same idea that <em>steveha</em> propose but with a different implementation (and only on the client side). Using a <code>datetime.datetime</code> object gives me a lot of nice features for working with dates (validation, comparaison, etc.).</p> <p>Secondly, I have created a <code>PartialDateField</code> that mostly deal with the conversion between the <code>PartialDate</code> object and the database.</p> <p>So far, it works pretty well (I have mostly finish my extensive unit tests).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload