Hi all,

Here’s an issue of usability that if fixed could make usage of custom fields 
simpler.

Right now fields don’t allow a built-in defaults, and you need to explicitly 
set the default parameter for model fields.  The problem is that this adds a 
ton of boilerplate code.

Using the Polls tutorial example, if I do:

>>> from polls.models import Question, Choice
>>> q = Question()

By default it’s always <class 'NoneType’>:

>>> type(q.pub_date)
<class 'NoneType'>

The pub_date should always be a type <class 'datetime.datetime'>.  If this was 
defined in the model constructor, then we could start to access the 
datetime.datetime class immediately, to assign data.  If I had a custom 
datetime.datetime class, I could possibly do this immediately:

>>> q = Question()
>>> q.pub_date.month = 11
>>> q.pub_date.day = 26
>>> q.pub_date.year = 2016
>>> q.save()

But right it would give the following error:

>>> q.pub_date.year = 2016
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'year'

Is this a reasonable request?  

I’m able to do something like this now with my own custom fields that derive 
from models.SubfieldBase, but that class is deprecated, and the new 1.8 model 
initializer doesn’t do this anymore.

Thank you,

-bobby

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1EBED647-BBA2-422B-A907-C9FBD6BC50F8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to