Beispiel #1
0
class Reporter(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.EmailField()

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

    def __str__(self):
        return ("%s %s" % (self.first_name, self.last_name)).strip()
Beispiel #2
0
class Category(models.Model):
    name = models.CharField(max_length=20)
    slug = models.SlugField(max_length=20)
    url = models.CharField('The URL', max_length=40)

    def __str__(self):
        return self.name

    def __repr__(self):
        return self.__str__()
Beispiel #3
0
class Employee(models.Model):
    employee_code = models.IntegerField(primary_key=True, db_column='code')
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)

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

    def __str__(self):
        return "%s %s" % (self.first_name, self.last_name)
Beispiel #4
0
class Employee(models.Model):
    name = models.CharField(max_length=40, blank=False, null=False)
    salary = models.PositiveIntegerField()
    department = models.CharField(max_length=40, blank=False, null=False)
    hire_date = models.DateField(blank=False, null=False)
    age = models.IntegerField(blank=False, null=False)

    def __str__(self):
        return '{}, {}, {}, {}'.format(self.name, self.department, self.salary,
                                       self.hire_date)
Beispiel #5
0
class ArticleTranslation(models.Model):
    article = models.ForeignKey(Article, models.CASCADE)
    lang = models.CharField(max_length=2)
    title = models.CharField(max_length=100)
    body = models.TextField()
    abstract = models.TextField(null=True)

    class Meta:
        unique_together = ('article', 'lang')
        ordering = ('active_translation__title', )
Beispiel #6
0
class Animal(models.Model):
    common_name = models.CharField(max_length=150)
    latin_name = models.CharField(max_length=150)

    tags = GenericRelation(TaggedItem, related_query_name='animal')
    comparisons = GenericRelation(Comparison,
                                  object_id_field="object_id1",
                                  content_type_field="content_type1")

    def __str__(self):
        return self.common_name
Beispiel #7
0
class GrandParent(models.Model):
    first_name = models.CharField(max_length=80)
    last_name = models.CharField(max_length=80)
    email = models.EmailField(unique=True)
    place = models.ForeignKey(Place,
                              models.CASCADE,
                              null=True,
                              related_name='+')

    class Meta:
        unique_together = ('first_name', 'last_name')
Beispiel #8
0
class Animal(models.Model):
    name = models.CharField(max_length=150)
    latin_name = models.CharField(max_length=150)
    count = models.IntegerField()
    weight = models.FloatField()

    # use a non-default name for the default manager
    specimens = models.Manager()

    def __str__(self):
        return self.name
Beispiel #9
0
 def test_serialize_fields(self):
     self.assertSerializedFieldEqual(models.CharField(max_length=255))
     self.assertSerializedResultEqual(models.CharField(max_length=255),
                                      ("models.CharField(max_length=255)",
                                       {"from djmodels.db import models"}))
     self.assertSerializedFieldEqual(models.TextField(null=True,
                                                      blank=True))
     self.assertSerializedResultEqual(
         models.TextField(null=True, blank=True),
         ("models.TextField(blank=True, null=True)",
          {'from djmodels.db import models'}))
Beispiel #10
0
class Author(models.Model):
    Author_ID = models.AutoField(primary_key=True, db_column='Author ID')
    first_name = models.CharField(max_length=30, db_column='firstname')
    last_name = models.CharField(max_length=30, db_column='last')

    def __str__(self):
        return '%s %s' % (self.first_name, self.last_name)

    class Meta:
        db_table = 'my_author_table'
        ordering = ('last_name', 'first_name')
Beispiel #11
0
class Address(models.Model):
    street = models.CharField(max_length=80)
    city = models.CharField(max_length=50)
    state = models.CharField(max_length=2)
    zipcode = models.CharField(max_length=5)
    content_type = models.ForeignKey(ContentType, models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey()

    def __str__(self):
        return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode)
Beispiel #12
0
class FlexibleDatePost(models.Model):
    title = models.CharField(max_length=50,
                             unique_for_date='posted',
                             blank=True)
    slug = models.CharField(max_length=50,
                            unique_for_year='posted',
                            blank=True)
    subtitle = models.CharField(max_length=50,
                                unique_for_month='posted',
                                blank=True)
    posted = models.DateField(blank=True, null=True)
Beispiel #13
0
    class Migration(models.Model):
        app = models.CharField(max_length=255)
        name = models.CharField(max_length=255)
        applied = models.DateTimeField(default=now)

        class Meta:
            apps = Apps()
            app_label = "migrations"
            db_table = "django_migrations"

        def __str__(self):
            return "Migration %s for %s" % (self.name, self.app)
Beispiel #14
0
class Request(models.Model):
    profile = models.ForeignKey(Profile,
                                models.SET_NULL,
                                null=True,
                                blank=True)
    location = models.ForeignKey(Location, models.CASCADE)
    items = models.ManyToManyField(Item)

    request1 = models.CharField(default='request1', max_length=255)
    request2 = models.CharField(default='request2', max_length=255)
    request3 = models.CharField(default='request3', max_length=255)
    request4 = models.CharField(default='request4', max_length=255)
Beispiel #15
0
class Article(models.Model):
    authors = models.ManyToManyField(Author, related_name='articles')
    title = models.CharField(max_length=50)
    summary = models.CharField(max_length=200, null=True, blank=True)
    text = models.TextField()
    written = models.DateTimeField()
    published = models.DateTimeField(null=True, blank=True)
    updated = models.DateTimeField(null=True, blank=True)
    views = models.PositiveIntegerField(default=0)

    def __str__(self):
        return self.title
Beispiel #16
0
class Book(models.Model):
    title = models.CharField(max_length=50)
    author = models.CharField(max_length=50)
    pages = models.IntegerField(db_column='page_count')
    shortcut = models.CharField(max_length=50, db_tablespace='idx_tbls')
    isbn = models.CharField(max_length=50, db_tablespace='idx_tbls')

    class Meta:
        indexes = [
            models.indexes.Index(fields=['title']),
            models.indexes.Index(fields=['isbn', 'id']),
        ]
Beispiel #17
0
class Migration(migrations.Migration):

    dependencies = [
        ('sites', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='FlatPage',
            fields=[
                ('id',
                 models.AutoField(verbose_name='ID',
                                  serialize=False,
                                  auto_created=True,
                                  primary_key=True)),
                ('url',
                 models.CharField(max_length=100,
                                  verbose_name='URL',
                                  db_index=True)),
                ('title', models.CharField(max_length=200,
                                           verbose_name='title')),
                ('content', models.TextField(verbose_name='content',
                                             blank=True)),
                ('enable_comments',
                 models.BooleanField(default=False,
                                     verbose_name='enable comments')),
                ('template_name',
                 models.CharField(help_text=(
                     "Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use "
                     "'flatpages/default.html'."),
                                  max_length=70,
                                  verbose_name='template name',
                                  blank=True)),
                ('registration_required',
                 models.BooleanField(
                     default=False,
                     help_text=
                     'If this is checked, only logged-in users will be able to view the page.',
                     verbose_name='registration required')),
                ('sites',
                 models.ManyToManyField(to='sites.Site',
                                        verbose_name='sites')),
            ],
            options={
                'ordering': ('url', ),
                'db_table': 'django_flatpage',
                'verbose_name': 'flat page',
                'verbose_name_plural': 'flat pages',
            },
            bases=(models.Model, ),
        ),
    ]
Beispiel #18
0
class Author(models.Model):
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    dob = models.DateField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Protect against annotations being passed to __init__ --
        # this'll make the test suite get angry if annotations aren't
        # treated differently than fields.
        for k in kwargs:
            assert k in [f.attname for f in self._meta.fields], \
                "Author.__init__ got an unexpected parameter: %s" % k
Beispiel #19
0
class Company(models.Model):
    name = models.CharField(max_length=200)
    motto = models.CharField(max_length=200, null=True, blank=True)
    ticker_name = models.CharField(max_length=10, null=True, blank=True)
    description = models.CharField(max_length=200, null=True, blank=True)

    def __str__(self):
        return 'Company(name=%s, motto=%s, ticker_name=%s, description=%s)' % (
            self.name,
            self.motto,
            self.ticker_name,
            self.description,
        )
Beispiel #20
0
class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

    def _get_full_name(self):
        return "%s %s" % (self.first_name, self.last_name)

    def _set_full_name(self, combined_name):
        self.first_name, self.last_name = combined_name.split(' ', 1)

    full_name = property(_get_full_name)

    full_name_2 = property(_get_full_name, _set_full_name)
Beispiel #21
0
class Employee(models.Model):
    # The order of these fields matter, do not change. Certain backends
    # rely on field ordering to perform database conversions, and this
    # model helps to test that.
    first_name = models.CharField(max_length=20)
    manager = models.BooleanField(default=False)
    last_name = models.CharField(max_length=20)
    store = models.ForeignKey(Store, models.CASCADE)
    age = models.IntegerField()
    salary = models.DecimalField(max_digits=8, decimal_places=2)

    def __str__(self):
        return '%s %s' % (self.first_name, self.last_name)
Beispiel #22
0
class Reporter(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.EmailField()
    facebook_user_id = models.BigIntegerField(null=True)
    raw_data = models.BinaryField(null=True)
    small_int = models.SmallIntegerField()

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

    def __str__(self):
        return "%s %s" % (self.first_name, self.last_name)
Beispiel #23
0
class PublicationDefaults(models.Model):
    MODE_CHOICES = (('di', 'direct'), ('de', 'delayed'))
    CATEGORY_CHOICES = ((1, 'Games'), (2, 'Comics'), (3, 'Novel'))
    title = models.CharField(max_length=30)
    date_published = models.DateField(default=datetime.date.today)
    datetime_published = models.DateTimeField(
        default=datetime.datetime(2000, 1, 1))
    mode = models.CharField(max_length=2,
                            choices=MODE_CHOICES,
                            default=default_mode)
    category = models.IntegerField(choices=CATEGORY_CHOICES,
                                   default=default_category)
    active = models.BooleanField(default=True)
    file = models.FileField(default='default.txt')
Beispiel #24
0
class DateTimePost(models.Model):
    title = models.CharField(max_length=50,
                             unique_for_date='posted',
                             blank=True)
    slug = models.CharField(max_length=50,
                            unique_for_year='posted',
                            blank=True)
    subtitle = models.CharField(max_length=50,
                                unique_for_month='posted',
                                blank=True)
    posted = models.DateTimeField(editable=False)

    def __str__(self):
        return self.title
Beispiel #25
0
class CategoryMetaData(models.Model):
    kind = models.CharField(max_length=10)
    name = models.CharField(max_length=10)
    value = models.CharField(max_length=10)
    objects = CategoryMetaDataManager()

    class Meta:
        unique_together = (('kind', 'name'), )

    def __str__(self):
        return '[%s:%s]=%s' % (self.kind, self.name, self.value)

    def natural_key(self):
        return (self.kind, self.name)
Beispiel #26
0
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,
                                models.CASCADE,
                                related_name='book_contact_set')
    publisher = models.ForeignKey(Publisher, models.CASCADE)
    pubdate = models.DateField()

    def __str__(self):
        return self.name
Beispiel #27
0
 def test_char_field(self):
     field = models.CharField(max_length=65)
     name, path, args, kwargs = field.deconstruct()
     self.assertEqual(path, "djmodels.db.models.CharField")
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {"max_length": 65})
     field = models.CharField(max_length=65, null=True, blank=True)
     name, path, args, kwargs = field.deconstruct()
     self.assertEqual(path, "djmodels.db.models.CharField")
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {
         "max_length": 65,
         "null": True,
         "blank": True
     })
Beispiel #28
0
 def test_add_field_rename_field(self):
     """
     RenameField should optimize into AddField
     """
     self.assertOptimizesTo(
         [
             migrations.AddField("Foo", "name",
                                 models.CharField(max_length=255)),
             migrations.RenameField("Foo", "name", "title"),
         ],
         [
             migrations.AddField("Foo", "title",
                                 models.CharField(max_length=255)),
         ],
     )
Beispiel #29
0
class Article(models.Model):
    title = models.CharField(max_length=50, unique=True)
    code = models.CharField(max_length=50,
                            unique=True,
                            db_tablespace='idx_tbsp')
    authors = models.ManyToManyField(Scientist,
                                     related_name='articles_written_set')
    reviewers = models.ManyToManyField(Scientist,
                                       related_name='articles_reviewed_set',
                                       db_tablespace='idx_tbsp')

    class Meta:
        db_table = 'model_options_articleref'
        db_tablespace = 'tbl_tbsp'
        managed = False
Beispiel #30
0
class Article(models.Model):
    headline = models.CharField(max_length=100)
    pub_date = models.DateField()
    expire_date = models.DateField()

    class Meta:
        get_latest_by = 'pub_date'