Skip to content

Commit b1a5a12

Browse files
committed
Add books Models
1 parent c199e2e commit b1a5a12

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

books/models.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
from django.db import models
22

3-
# Create your models here.
3+
4+
class Book(models.Model):
5+
title = models.CharField(max_length=100)
6+
authors = models.ManyToManyField('Author')
7+
publisher = models.ForeignKey(Publisher)
8+
publication_date = models.DateField()
9+
10+
def __unicode__(self): # __str__ on Python 3
11+
return self.title
12+
13+
14+
class Author(models.Model):
15+
salutation = models.CharField(max_length=100)
16+
name = models.CharField(max_length=50)
17+
email = models.EmailField()
18+
19+
def __unicode__(self):
20+
return self.name
21+
22+
23+
class Publisher(models.Model):
24+
name = models.CharField(max_length=50)
25+
address = models.CharField(max_length=100)
26+
website = models.URLField()
27+
28+
def __unicode__(self):
29+
return self.name

0 commit comments

Comments
 (0)