2013-02-05 00:55:35 +04:00
|
|
|
from __future__ import unicode_literals
|
2012-09-20 16:06:27 +04:00
|
|
|
from django.db import models
|
2012-12-03 22:07:07 +04:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2012-10-05 01:07:24 +04:00
|
|
|
|
2012-09-28 17:28:50 +04:00
|
|
|
|
2012-10-04 12:19:10 +04:00
|
|
|
class RESTFrameworkModel(models.Model):
|
2012-10-03 13:51:38 +04:00
|
|
|
"""
|
2012-10-04 12:18:46 +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:
|
2012-10-27 21:44:23 +04:00
|
|
|
app_label = 'tests'
|
2012-10-04 12:18:46 +04:00
|
|
|
abstract = True
|
2012-10-03 13:51:38 +04:00
|
|
|
|
2012-09-28 17:28:50 +04:00
|
|
|
|
2012-10-04 12:19:10 +04:00
|
|
|
class BasicModel(RESTFrameworkModel):
|
2013-05-18 18:42:54 +04:00
|
|
|
text = models.CharField(max_length=100, verbose_name=_("Text comes here"), help_text=_("Text description."))
|
2012-10-03 13:51:38 +04:00
|
|
|
|
|
|
|
|
2014-02-09 09:50:03 +04:00
|
|
|
class BaseFilterableItem(RESTFrameworkModel):
|
|
|
|
text = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
class FilterableItem(BaseFilterableItem):
|
|
|
|
decimal = models.DecimalField(max_digits=4, decimal_places=2)
|
|
|
|
date = models.DateField()
|
|
|
|
|
|
|
|
|
2013-01-03 13:23:13 +04:00
|
|
|
# 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 ForeignKeySource(RESTFrameworkModel):
|
|
|
|
name = models.CharField(max_length=100)
|
2014-03-30 13:48:17 +04:00
|
|
|
target = models.ForeignKey(ForeignKeyTarget, related_name='sources',
|
2014-04-24 13:58:53 +04:00
|
|
|
help_text='Target', verbose_name='Target')
|
2013-01-03 13:23:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
# Nullable ForeignKey
|
|
|
|
class NullableForeignKeySource(RESTFrameworkModel):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
2014-03-30 13:48:17 +04:00
|
|
|
related_name='nullable_sources',
|
|
|
|
verbose_name='Optional target object')
|
2013-01-05 00:11:03 +04:00
|
|
|
|
2013-01-08 04:27:31 +04:00
|
|
|
|
|
|
|
# OneToOne
|
|
|
|
class OneToOneTarget(RESTFrameworkModel):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
|
2013-01-05 00:11:03 +04:00
|
|
|
class NullableOneToOneSource(RESTFrameworkModel):
|
|
|
|
name = models.CharField(max_length=100)
|
2013-01-08 04:27:31 +04:00
|
|
|
target = models.OneToOneField(OneToOneTarget, null=True, blank=True,
|
2013-01-05 00:11:03 +04:00
|
|
|
related_name='nullable_source')
|