2007-03-01 13:11:08 +00:00
|
|
|
"""
|
2014-09-24 05:13:13 +00:00
|
|
|
Fixtures.
|
2007-03-01 13:11:08 +00:00
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
Fixtures are a way of loading data into the database in bulk. Fixure data
|
|
|
|
can be stored in any serializable format (including JSON and XML). Fixtures
|
2007-03-01 13:11:08 +00:00
|
|
|
are identified by name, and are stored in either a directory named 'fixtures'
|
2010-12-14 00:37:42 +00:00
|
|
|
in the application directory, or in one of the directories named in the
|
2008-08-12 14:15:38 +00:00
|
|
|
``FIXTURE_DIRS`` setting.
|
2007-03-01 13:11:08 +00:00
|
|
|
"""
|
|
|
|
|
2016-07-16 10:27:25 +00:00
|
|
|
import uuid
|
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
from django.contrib.auth.models import Permission
|
2014-01-22 06:43:33 +00:00
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
2009-12-14 12:39:20 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-13 18:04:12 +00:00
|
|
|
from django.db import models
|
2007-03-01 13:11:08 +00:00
|
|
|
|
2009-12-22 15:18:51 +00:00
|
|
|
|
2009-02-28 05:35:22 +00:00
|
|
|
class Category(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
description = models.TextField()
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-02-28 05:35:22 +00:00
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2007-03-01 13:11:08 +00:00
|
|
|
class Article(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
headline = models.CharField(max_length=100, default='Default headline')
|
2007-03-01 13:11:08 +00:00
|
|
|
pub_date = models.DateTimeField()
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2007-03-01 13:11:08 +00:00
|
|
|
return self.headline
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
|
2007-03-01 13:11:08 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('-pub_date', 'headline')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Blog(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2015-07-22 14:43:21 +00:00
|
|
|
featured = models.ForeignKey(Article, models.CASCADE, related_name='fixtures_featured_set')
|
2009-12-14 12:39:20 +00:00
|
|
|
articles = models.ManyToManyField(Article, blank=True,
|
|
|
|
related_name='fixtures_articles_set')
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-12-14 12:39:20 +00:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2015-07-22 14:43:21 +00:00
|
|
|
tagged_type = models.ForeignKey(ContentType, models.CASCADE, related_name="fixtures_tag_set")
|
2009-12-14 12:39:20 +00:00
|
|
|
tagged_id = models.PositiveIntegerField(default=0)
|
2014-01-22 06:43:33 +00:00
|
|
|
tagged = GenericForeignKey(ct_field='tagged_type', fk_field='tagged_id')
|
2009-12-14 12:39:20 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-12-14 12:39:20 +00:00
|
|
|
return '<%s: %s> tagged "%s"' % (self.tagged.__class__.__name__,
|
|
|
|
self.tagged, self.name)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class PersonManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, name):
|
|
|
|
return self.get(name=name)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Person(models.Model):
|
|
|
|
objects = PersonManager()
|
|
|
|
name = models.CharField(max_length=100)
|
2013-10-22 10:21:07 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-12-14 12:39:20 +00:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.name,)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-08-30 11:58:26 +00:00
|
|
|
class SpyManager(PersonManager):
|
2013-03-08 14:15:23 +00:00
|
|
|
def get_queryset(self):
|
2017-01-21 13:13:44 +00:00
|
|
|
return super().get_queryset().filter(cover_blown=False)
|
2010-08-30 11:58:26 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-08-30 11:58:26 +00:00
|
|
|
class Spy(Person):
|
|
|
|
objects = SpyManager()
|
|
|
|
cover_blown = models.BooleanField(default=False)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2016-01-27 11:15:38 +00:00
|
|
|
class ProxySpy(Spy):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Visa(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
person = models.ForeignKey(Person, models.CASCADE)
|
2009-12-14 12:39:20 +00:00
|
|
|
permissions = models.ManyToManyField(Permission, blank=True)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-12-14 12:39:20 +00:00
|
|
|
return '%s %s' % (self.person.name,
|
|
|
|
', '.join(p.name for p in self.permissions.all()))
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
authors = models.ManyToManyField(Person)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2011-11-27 13:00:56 +00:00
|
|
|
authors = ' and '.join(a.name for a in self.authors.all())
|
|
|
|
return '%s by %s' % (self.name, authors) if authors else self.name
|
2009-12-14 12:39:20 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
2016-07-16 10:27:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PrimaryKeyUUIDModel(models.Model):
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
|