como definir modelos con django

Solutions on MaxInterview for como definir modelos con django by the best coders in the world

showing results for - "como definir modelos con django"
Anna
24 May 2016
1from django.db import models
2from django.utils import timezone
3
4
5class Post(models.Model):
6    author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
7    title = models.CharField(max_length=200)
8    text = models.TextField()
9    created_date = models.DateTimeField(
10            default=timezone.now)
11    published_date = models.DateTimeField(
12            blank=True, null=True)
13
14    def publish(self):
15        self.published_date = timezone.now()
16        self.save()
17
18    def __str__(self):
19        return self.title
20