D
D
DenGit20182018-03-22 17:47:43
Django
DenGit2018, 2018-03-22 17:47:43

How to properly return data from the model?

There is a model:

class Post(models.Model):
    post = models.CharField(max_length=500)
    user = models.ForeignKey(User)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user_pk  = models.IntegerField(default=0)
    user_send = models.IntegerField(default=0)

How to return the date? Like how it's done with text
def __str__(self):
        return self.post

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-03-22
@DenGit2018

The model is the data.

last_post = Post.objects.last()
print(last_post.created)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question