django-rest-framework/tests/models.py

91 lines
2.6 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2016-02-16 11:29:48 +03:00
import uuid
from django.db import models
2012-12-03 22:07:07 +04:00
from django.utils.translation import ugettext_lazy as _
2012-09-28 17:28:50 +04:00
class RESTFrameworkModel(models.Model):
2012-10-03 13:51:38 +04:00
"""
Base for test models that sets app_label, so they play nicely.
2012-10-03 13:51:38 +04:00
"""
2014-11-29 21:45:26 +03:00
2012-10-03 13:51:38 +04:00
class Meta:
app_label = 'tests'
abstract = True
2012-10-03 13:51:38 +04:00
2012-09-28 17:28:50 +04:00
class BasicModel(RESTFrameworkModel):
text = models.CharField(
max_length=100,
verbose_name=_("Text comes here"),
help_text=_("Text description.")
)
2012-10-03 13:51:38 +04:00
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)
2016-02-16 11:29:48 +03:00
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)
2016-02-16 11:29:48 +03:00
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)