2007-03-01 13:11:08 +00:00
|
|
|
"""
|
2007-03-23 20:17:04 +00:00
|
|
|
37. 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'
|
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
|
|
|
in the application directory, on 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
|
|
|
"""
|
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2009-12-22 15:18:51 +00:00
|
|
|
from django.db import models, DEFAULT_DB_ALIAS
|
2007-09-16 10:04:03 +00:00
|
|
|
from django.conf import settings
|
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()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
|
|
|
|
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()
|
|
|
|
|
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
|
|
|
def __unicode__(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
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Blog(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
featured = models.ForeignKey(Article, related_name='fixtures_featured_set')
|
|
|
|
articles = models.ManyToManyField(Article, blank=True,
|
|
|
|
related_name='fixtures_articles_set')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
tagged_type = models.ForeignKey(ContentType, related_name="fixtures_tag_set")
|
|
|
|
tagged_id = models.PositiveIntegerField(default=0)
|
|
|
|
tagged = generic.GenericForeignKey(ct_field='tagged_type',
|
|
|
|
fk_field='tagged_id')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return '<%s: %s> tagged "%s"' % (self.tagged.__class__.__name__,
|
|
|
|
self.tagged, self.name)
|
|
|
|
|
|
|
|
class PersonManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, name):
|
|
|
|
return self.get(name=name)
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
objects = PersonManager()
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.name,)
|
|
|
|
|
2010-08-30 11:58:26 +00:00
|
|
|
class SpyManager(PersonManager):
|
|
|
|
def get_query_set(self):
|
|
|
|
return super(SpyManager, self).get_query_set().filter(cover_blown=False)
|
|
|
|
|
|
|
|
class Spy(Person):
|
|
|
|
objects = SpyManager()
|
|
|
|
cover_blown = models.BooleanField(default=False)
|
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Visa(models.Model):
|
|
|
|
person = models.ForeignKey(Person)
|
|
|
|
permissions = models.ManyToManyField(Permission, blank=True)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return '%s %s' % (self.person.name,
|
|
|
|
', '.join(p.name for p in self.permissions.all()))
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
authors = models.ManyToManyField(Person)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return '%s by %s' % (self.name,
|
|
|
|
' and '.join(a.name for a in self.authors.all()))
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|