Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of string argument in django model's Field?

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?

like image 351
null Avatar asked Nov 22 '14 12:11

null


People also ask

What is __ str __ In Django model?

str function in a django model returns a string that is exactly rendered as the display name of instances for that model.

What does CharField mean in Django?

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.


2 Answers

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')

enter image description here

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}]
like image 152
Tanveer Alam Avatar answered Oct 14 '22 11:10

Tanveer Alam


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')
like image 26
Mark Chackerian Avatar answered Oct 14 '22 11:10

Mark Chackerian