Пример #1
0
class Book(models.Model):
    name = models.CharField(max_length=100)
    author = models.CharField(max_length=100)
    id = models.CompositeField(author, name, primary_key=True)

    def __unicode__(self):
        return u"%s (by %s)" % (self.name, self.author)
Пример #2
0
class BookLibraryM2M(models.Model):
    book = models.ForeignKey(Book)
    library = models.ForeignKey(Library)
    id = models.CompositeField(book, library, primary_key=True)

    class Meta:
        auto_created = Library
Пример #3
0
class Author(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()
    friends = models.ManyToManyField('self', blank=True)
    id = models.CompositeField(name, age, primary_key=True)

    def __unicode__(self):
        return self.name
Пример #4
0
class Employee(models.Model):
    employee_code = models.IntegerField(db_column='code')
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    id = models.CompositeField(employee_code, last_name, primary_key=True)

    class Meta:
        ordering = ('last_name', 'first_name')

    def __unicode__(self):
        return u"%s %s" % (self.first_name, self.last_name)
Пример #5
0
class AbstractChapter(models.Model):
    author = models.CharField(max_length=100,
                              db_column="b1_author",
                              name="_author")
    name = models.CharField(max_length=100, db_column="b1_name", name="_name")
    book = models.ForeignKey(Book,
                             fields=(author, name),
                             related_name="chapter_set")
    num = models.PositiveSmallIntegerField()
    title = models.CharField(max_length=100)
    id = models.CompositeField(book, num, primary_key=True)

    class Meta:
        abstract = True

    def __unicode__(self):
        return u"%s (%s) %s" % (self._name, self.num, self._author)