Just learning django, I'm reading this tutorial and getting confused at this part:
class Question(models.Model):
pub_date = models.DateTimeField('date published')
Having searching its documentation, still can't figure out what does 'date published'
argument mean? Anyone can explain?
str function in a django model returns a string that is exactly rendered as the display name of instances for that model.
CharField is a string field, for small- to large-sized strings. It is like a string field in C/C+++. CharField is generally used for storing small strings like first name, last name, etc. To store larger text TextField is used. The default form widget for this field is TextInput.
Well here is an example of what human-readable name means.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('Enter published date')
So in our admin panel we see our pub_date feild name as Enter published date.
But if you try to fetch data from database you will see the feild name as pub_date.
>>> data_dict = Question.objects.all().values()
>>> data_dict
[{'question_text': u'What is Python?', 'pub_date': datetime.datetime(2014, 11, 22, 12, 23, 42, tzinfo=<UTC>), u'id': 1}]
Because this feature is hard to find in the documentation, I think it's better practice to explicitly use the verbose_name argument, e.g.
class Question(models.Model):
pub_date = models.DateTimeField(verbose_name='date published')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With