mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 03:54:01 +03:00
994e1ba927
* Added TEMPLATES setting to tests * Remove deprecated view-string in URL conf * Replace 'urls = ...' in test classes with override_settings('ROOT_URLCONF=...') * Refactor UsingURLPatterns to use override_settings(ROOT_URLCONF=...) style * Get model managers and names in a version-compatible manner. * Apply override_settings to a TestCase, not a mixin class * Use '.callback' property instead of private attributes when inspecting urlpatterns * Pass 'user' to template explicitly * Correct sorting of import statements. * Remove unused TEMPLATE_LOADERS setting, in favor of TEMPLATES. * Remove code style issue * BaseFilter test requires a concrete model * Resolve tox.ini issues * Resolve isort differences between local and tox environments
91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
from __future__ import unicode_literals
|
|
|
|
import uuid
|
|
|
|
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
class RESTFrameworkModel(models.Model):
|
|
"""
|
|
Base for test models that sets app_label, so they play nicely.
|
|
"""
|
|
|
|
class Meta:
|
|
app_label = 'tests'
|
|
abstract = True
|
|
|
|
|
|
class BasicModel(RESTFrameworkModel):
|
|
text = models.CharField(
|
|
max_length=100,
|
|
verbose_name=_("Text comes here"),
|
|
help_text=_("Text description.")
|
|
)
|
|
|
|
|
|
class BaseFilterableItem(RESTFrameworkModel):
|
|
text = models.CharField(max_length=100)
|
|
|
|
|
|
class FilterableItem(BaseFilterableItem):
|
|
decimal = models.DecimalField(max_digits=4, decimal_places=2)
|
|
date = models.DateField()
|
|
|
|
|
|
# Models for relations tests
|
|
# ManyToMany
|
|
class ManyToManyTarget(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
class ManyToManySource(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
targets = models.ManyToManyField(ManyToManyTarget, related_name='sources')
|
|
|
|
|
|
# ForeignKey
|
|
class ForeignKeyTarget(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
class UUIDForeignKeyTarget(RESTFrameworkModel):
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
class ForeignKeySource(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
target = models.ForeignKey(ForeignKeyTarget, related_name='sources',
|
|
help_text='Target', verbose_name='Target',
|
|
on_delete=models.CASCADE)
|
|
|
|
|
|
# Nullable ForeignKey
|
|
class NullableForeignKeySource(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
|
related_name='nullable_sources',
|
|
verbose_name='Optional target object',
|
|
on_delete=models.CASCADE)
|
|
|
|
|
|
class NullableUUIDForeignKeySource(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
|
related_name='nullable_sources',
|
|
verbose_name='Optional target object',
|
|
on_delete=models.CASCADE)
|
|
|
|
|
|
# OneToOne
|
|
class OneToOneTarget(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
class NullableOneToOneSource(RESTFrameworkModel):
|
|
name = models.CharField(max_length=100)
|
|
target = models.OneToOneField(
|
|
OneToOneTarget, null=True, blank=True,
|
|
related_name='nullable_source', on_delete=models.CASCADE)
|