Created
September 13, 2019 20:35
-
-
Save goutomroy/a3c5631bd952d733b2f86e851c90cfe1 to your computer and use it in GitHub Desktop.
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
class Author(models.Model): | |
name = models.CharField(max_length=200) | |
email = models.EmailField() | |
def __str__(self): | |
return self.name | |
@property | |
def url(self): | |
return 'author/' + str(self.id) | |
class Blog(models.Model): | |
name = models.CharField(max_length=100) | |
tagline = models.TextField(blank=True, null=True) | |
class Meta: | |
default_related_name = 'blogs' | |
@property | |
def num_of_entries(self): | |
return str(self.entries.count()) | |
def __str__(self): | |
return self.name | |
class Entry(models.Model): | |
blog = models.ForeignKey(Blog, on_delete=models.CASCADE, blank=True, null=True) | |
headline = models.CharField(max_length=255) | |
body_text = models.TextField(blank=True, null=True) | |
pub_date = models.DateField(blank=True, null=True) | |
mod_date = models.DateField(blank=True, null=True) | |
authors = models.ManyToManyField(Author, blank=True, null=True) | |
n_comments = models.IntegerField(default=0) | |
n_pingbacks = models.IntegerField(default=0) | |
rating = models.IntegerField(default=0) | |
class Meta: | |
default_related_name = 'entries' | |
@property | |
def num_of_authors(self): | |
return str(self.authors.count()) | |
@property | |
def name_of_authors(self): | |
names = '-'.join([each.name for each in self.authors.all()]) | |
return names | |
def __str__(self): | |
return self.headline + " " + str(self.pub_date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment