Last active
June 7, 2019 18:22
-
-
Save goutomroy/4d7281d4c927ede791c509a59b1ed44c to your computer and use it in GitHub Desktop.
Model example to understand queryset operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Blog(models.Model): | |
name = models.CharField(max_length=100) | |
tagline = models.TextField() | |
def __str__(self): | |
return self.name | |
class Entry(models.Model): | |
blog = models.ForeignKey(Blog, on_delete=models.CASCADE) | |
headline = models.CharField(max_length=255) | |
body_text = models.TextField(blank=True) | |
class Meta: | |
default_related_name = 'entries' | |
def __str__(self): | |
return self.headline | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment