mirror of
https://github.com/django/django.git
synced 2024-12-27 11:35:53 +00:00
d4a0b27838
* Renamed the __unicode__ methods * Applied the python_2_unicode_compatible decorator * Removed the StrAndUnicode mix-in that is superseded by python_2_unicode_compatible * Kept the __unicode__ methods in classes that specifically test it under Python 2
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
# coding: utf-8
|
|
from django.db import models
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class Author(models.Model):
|
|
name = models.CharField(max_length=100)
|
|
age = models.IntegerField()
|
|
friends = models.ManyToManyField('self', blank=True)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@python_2_unicode_compatible
|
|
class Publisher(models.Model):
|
|
name = models.CharField(max_length=255)
|
|
num_awards = models.IntegerField()
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@python_2_unicode_compatible
|
|
class Book(models.Model):
|
|
isbn = models.CharField(max_length=9)
|
|
name = models.CharField(max_length=255)
|
|
pages = models.IntegerField()
|
|
rating = models.FloatField()
|
|
price = models.DecimalField(decimal_places=2, max_digits=6)
|
|
authors = models.ManyToManyField(Author)
|
|
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
|
publisher = models.ForeignKey(Publisher)
|
|
pubdate = models.DateField()
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@python_2_unicode_compatible
|
|
class Store(models.Model):
|
|
name = models.CharField(max_length=255)
|
|
books = models.ManyToManyField(Book)
|
|
original_opening = models.DateTimeField()
|
|
friday_night_closing = models.TimeField()
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|