Commit 666a2ad2 authored by Claude Paroz's avatar Claude Paroz
Browse files

Merged model_forms_regress with model_forms tests

parent 72cfbdc1
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
from django.utils._os import upath


temp_storage_dir = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
@@ -36,6 +37,10 @@ ARTICLE_STATUS_CHAR = (
)


class Person(models.Model):
    name = models.CharField(max_length=100)


@python_2_unicode_compatible
class Category(models.Model):
    name = models.CharField(max_length=20)
@@ -92,6 +97,25 @@ class BetterWriter(Writer):
    score = models.IntegerField()


@python_2_unicode_compatible
class Publication(models.Model):
    title = models.CharField(max_length=30)
    date_published = models.DateField()

    def __str__(self):
        return self.title


class Author(models.Model):
    publication = models.OneToOneField(Publication, null=True, blank=True)
    full_name = models.CharField(max_length=255)


class Author1(models.Model):
    publication = models.OneToOneField(Publication, null=False)
    full_name = models.CharField(max_length=255)


@python_2_unicode_compatible
class WriterProfile(models.Model):
    writer = models.OneToOneField(Writer, primary_key=True)
@@ -101,6 +125,10 @@ class WriterProfile(models.Model):
        return "%s is %s" % (self.writer, self.age)


class Document(models.Model):
    myfile = models.FileField(upload_to='unused', blank=True)


@python_2_unicode_compatible
class TextFile(models.Model):
    description = models.CharField(max_length=20)
@@ -109,6 +137,22 @@ class TextFile(models.Model):
    def __str__(self):
        return self.description


class CustomFileField(models.FileField):
    def save_form_data(self, instance, data):
        been_here = getattr(self, 'been_saved', False)
        assert not been_here, "save_form_data called more than once"
        setattr(self, 'been_saved', True)


class CustomFF(models.Model):
    f = CustomFileField(upload_to='unused', blank=True)


class FilePathModel(models.Model):
    path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)


try:
    from django.utils.image import Image  # NOQA: detect if Pillow is installed

@@ -161,6 +205,10 @@ class CommaSeparatedInteger(models.Model):
        return self.field


class Homepage(models.Model):
    url = models.URLField()


@python_2_unicode_compatible
class Product(models.Model):
    slug = models.SlugField(unique=True)
@@ -181,6 +229,15 @@ class Price(models.Model):
        unique_together = (('price', 'quantity'),)


class Triple(models.Model):
    left = models.IntegerField()
    middle = models.IntegerField()
    right = models.IntegerField()

    class Meta:
        unique_together = (('left', 'middle'), ('middle', 'right'))


class ArticleStatus(models.Model):
    status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True)

@@ -329,6 +386,8 @@ class CustomErrorMessage(models.Model):
    def clean(self):
        if self.name1 == 'FORBIDDEN_VALUE':
            raise ValidationError({'name1': [ValidationError('Model.clean() error messages.')]})
        elif self.name1 == 'GLOBAL_ERROR':
            raise ValidationError("Global error message.")


def today_callable_dict():
+604 −77

File changed.

Preview size limit exceeded, changes collapsed.

+0 −0

Empty file deleted.

+0 −90
Original line number Diff line number Diff line
from __future__ import unicode_literals

import os

from django.core.exceptions import ValidationError
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils._os import upath


class Person(models.Model):
    name = models.CharField(max_length=100)


class Triple(models.Model):
    left = models.IntegerField()
    middle = models.IntegerField()
    right = models.IntegerField()

    class Meta:
        unique_together = (('left', 'middle'), ('middle', 'right'))


class FilePathModel(models.Model):
    path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)


@python_2_unicode_compatible
class Publication(models.Model):
    title = models.CharField(max_length=30)
    date_published = models.DateField()

    def __str__(self):
        return self.title


@python_2_unicode_compatible
class Article(models.Model):
    headline = models.CharField(max_length=100)
    publications = models.ManyToManyField(Publication)

    def __str__(self):
        return self.headline


class CustomFileField(models.FileField):
    def save_form_data(self, instance, data):
        been_here = getattr(self, 'been_saved', False)
        assert not been_here, "save_form_data called more than once"
        setattr(self, 'been_saved', True)


class CustomFF(models.Model):
    f = CustomFileField(upload_to='unused', blank=True)


class RealPerson(models.Model):
    name = models.CharField(max_length=100)

    def clean(self):
        if self.name.lower() == 'anonymous':
            raise ValidationError("Please specify a real name.")


class Author(models.Model):
    publication = models.OneToOneField(Publication, null=True, blank=True)
    full_name = models.CharField(max_length=255)


class Author1(models.Model):
    publication = models.OneToOneField(Publication, null=False)
    full_name = models.CharField(max_length=255)


class Homepage(models.Model):
    url = models.URLField()


class Document(models.Model):
    myfile = models.FileField(upload_to='unused', blank=True)


class Edition(models.Model):
    author = models.ForeignKey(Person)
    publication = models.ForeignKey(Publication)
    edition = models.IntegerField()
    isbn = models.CharField(max_length=13, unique=True)

    class Meta:
        unique_together = (('author', 'publication'), ('publication', 'edition'),)
+0 −604

File deleted.

Preview size limit exceeded, changes collapsed.