Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goutomroy/4d7281d4c927ede791c509a59b1ed44c to your computer and use it in GitHub Desktop.
Save goutomroy/4d7281d4c927ede791c509a59b1ed44c to your computer and use it in GitHub Desktop.
Model example to understand queryset operations
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