Created
June 6, 2019 12:31
-
-
Save goutomroy/153152b4d005aed5fb3654ef4a50d4ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Publisher(models.Model): | |
name = models.CharField(max_length=300) | |
def __str__(self): | |
return self.name | |
class Book(models.Model): | |
name = models.CharField(max_length=300) | |
price = models.IntegerField(default=0) | |
publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE) | |
class Meta: | |
default_related_name = 'books' | |
def __str__(self): | |
return self.name | |
class Store(models.Model): | |
name = models.CharField(max_length=300) | |
books = models.ManyToManyField(Book) | |
class Meta: | |
default_related_name = 'stores' | |
def __str__(self): | |
return self.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment