Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Can I store full dates (mmddyyyy) and year-only dates (yyyy) in the same field? [RSS Feed]

#1 Jan. 25, 2011 16:50:41

Karen M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Can I store full dates (mmddyyyy) and year-only dates (yyyy) in the same field?


Hello,

I'm designing a model which is a collection of texts. Some of the
texts will be things like books, with a YYYY date of publication, and
some of them will be articles or transcripts with a mmddyyy date of
publication/broadcast.

I'd like to structure it somehow so that when I view the list of texts
in the admin site, I see something like this:


Title Date ...other
fields
----------------------------------------------------------------------------------
Sample Book 1984 ...
Sample Blog Post 1/14/2010 ...


Can I (should I?) store these two kinds of dates in one field? If I
can't (or shouldn't), is there some other way to accomplish this
(that's not too complicated)?

Thanks,
Karen

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 25, 2011 19:22:53

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Can I store full dates (mmddyyyy) and year-only dates (yyyy) in the same field?


Malcolm Tredinnick gave a talk at Djangocon last year that touched on
this. He used a similar approach to Tim. Essentially he had a model
that had a DateField and a precision.

Malcolm has his slides up:https://github.com/malcolmt/django-modeling-examples/blob/master/slides/modeling-challenges.pdfOn Jan 25, 9:16 am, "Tim Sawyer" <list.dja...@calidris.co.uk> wrote:
> Hi Karen,
>
> I did with two fields - storing a date and a date resolution.
>
> The values could be:
>
> date / resolution - display value
>
> 1984-12-31 / Exact Date - 31st December 1984
> 1984-12-01 / Month - December 1984
> 1984-01-01 / Year - 1984
>
> So I just used the first of the month where unknown, and January where
> unknown.
>
> I then had a method on the model object to return the format based on the
> stored date and the resolution.
>
> It worked for what I needed it for,
>
> Tim.
>
>
>
>
>
>
>
> > Hello,
>
> > I'm designing a model which is a collection of texts.  Some of the
> > texts will be things like books, with a YYYY date of publication, and
> > some of them will be articles or transcripts with a mmddyyy date of
> > publication/broadcast.
>
> > I'd like to structure it somehow so that when I view the list of texts
> > in the admin site, I see something like this:
>
> > Title                            Date                      ...other
> > fields
> > ---------------------------------------------------------------------------
> > -------
> > Sample Book               1984                     ...
> > Sample Blog Post         1/14/2010             ...
>
> > Can I (should I?) store these two kinds of dates in one field?  If I
> > can't (or shouldn't), is there some other way to accomplish this
> > (that's not too complicated)?
>
> > Thanks,
> > Karen
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 26, 2011 01:08:27

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Can I store full dates (mmddyyyy) and year-only dates (yyyy) in the same field?


I had this need some time ago. You can check the answers of my
question on stackoverflow for different avenues:http://stackoverflow.com/questions/2971198/how-to-deal-with-partial-dates-2010-00-00-from-mysql-in-djangoEtienne

On Jan 25, 7:22 pm, David <djfis...@gmail.com> wrote:
> Malcolm Tredinnick gave a talk at Djangocon last year that touched on
> this. He used a similar approach to Tim. Essentially he had a model
> that had a DateField and a precision.
>
> Malcolm has his slides
> up:https://github.com/malcolmt/django-modeling-examples/blob/master/slid...
>
> On Jan 25, 9:16 am, "Tim Sawyer" <list.dja...@calidris.co.uk> wrote:
>
> > Hi Karen,
>
> > I did with two fields - storing a date and a date resolution.
>
> > The values could be:
>
> > date / resolution - display value
>
> > 1984-12-31 / Exact Date - 31st December 1984
> > 1984-12-01 / Month - December 1984
> > 1984-01-01 / Year - 1984
>
> > So I just used the first of the month where unknown, and January where
> > unknown.
>
> > I then had a method on the model object to return the format based on the
> > stored date and the resolution.
>
> > It worked for what I needed it for,
>
> > Tim.
>
> > > Hello,
>
> > > I'm designing a model which is a collection of texts.  Some of the
> > > texts will be things like books, with a YYYY date of publication, and
> > > some of them will be articles or transcripts with a mmddyyy date of
> > > publication/broadcast.
>
> > > I'd like to structure it somehow so that when I view the list of texts
> > > in the admin site, I see something like this:
>
> > > Title                            Date                      ...other
> > > fields
> > > ---------------------------------------------------------------------------
> > > -------
> > > Sample Book               1984                     ...
> > > Sample Blog Post         1/14/2010             ...
>
> > > Can I (should I?) store these two kinds of dates in one field?  If I
> > > can't (or shouldn't), is there some other way to accomplish this
> > > (that's not too complicated)?
>
> > > Thanks,
> > > Karen
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Can I store full dates (mmddyyyy) and year-only dates (yyyy) in the same field? [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support