Here is my code
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
So I'm kinda confused with what models.DateTimeField(default=timezone.now)
do, what does "default" mean here?
And I'm also confused what models.ForeignKey(User, on_delete=models.CASCADE)
do, what is "on_delete=models.CASCADE" do and mean?
And is this code ( from django.contrib.auth.models
) a database for users?
Aucun commentaire:
Enregistrer un commentaire