mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 21:14:01 +03:00
Move relation tests models into models.py
This commit is contained in:
parent
ed9f20823b
commit
8fd1f09dad
|
@ -176,3 +176,31 @@ class OptionalRelationModel(RESTFrameworkModel):
|
||||||
# Model for RegexField
|
# Model for RegexField
|
||||||
class Book(RESTFrameworkModel):
|
class Book(RESTFrameworkModel):
|
||||||
isbn = models.CharField(max_length=13)
|
isbn = models.CharField(max_length=13)
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
target = models.ForeignKey(ForeignKeyTarget, related_name='sources')
|
||||||
|
|
||||||
|
|
||||||
|
# Nullable ForeignKey
|
||||||
|
class NullableForeignKeySource(RESTFrameworkModel):
|
||||||
|
name = models.CharField(max_length=100)
|
||||||
|
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
||||||
|
related_name='nullable_sources')
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.compat import patterns, url
|
from rest_framework.compat import patterns, url
|
||||||
|
from rest_framework.tests.models import ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource
|
||||||
|
|
||||||
def dummy_view(request, pk):
|
def dummy_view(request, pk):
|
||||||
pass
|
pass
|
||||||
|
@ -15,18 +15,6 @@ urlpatterns = patterns('',
|
||||||
url(r'^nullableforeignkeysource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableforeignkeysource-detail'),
|
url(r'^nullableforeignkeysource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableforeignkeysource-detail'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# ManyToMany
|
|
||||||
|
|
||||||
class ManyToManyTarget(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
|
|
||||||
class ManyToManySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
targets = models.ManyToManyField(ManyToManyTarget, related_name='sources')
|
|
||||||
|
|
||||||
|
|
||||||
class ManyToManyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
class ManyToManyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
sources = serializers.ManyHyperlinkedRelatedField(view_name='manytomanysource-detail')
|
sources = serializers.ManyHyperlinkedRelatedField(view_name='manytomanysource-detail')
|
||||||
|
|
||||||
|
@ -39,17 +27,6 @@ class ManyToManySourceSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
model = ManyToManySource
|
model = ManyToManySource
|
||||||
|
|
||||||
|
|
||||||
# ForeignKey
|
|
||||||
|
|
||||||
class ForeignKeyTarget(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
target = models.ForeignKey(ForeignKeyTarget, related_name='sources')
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
class ForeignKeyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
sources = serializers.ManyHyperlinkedRelatedField(view_name='foreignkeysource-detail')
|
sources = serializers.ManyHyperlinkedRelatedField(view_name='foreignkeysource-detail')
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.tests.models import ForeignKeyTarget, ForeignKeySource, NullableForeignKeySource
|
||||||
|
|
||||||
# ForeignKey
|
|
||||||
|
|
||||||
class ForeignKeyTarget(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
target = models.ForeignKey(ForeignKeyTarget, related_name='sources')
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeySourceSerializer(serializers.ModelSerializer):
|
class ForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||||
|
@ -32,14 +22,6 @@ class ForeignKeyTargetSerializer(serializers.ModelSerializer):
|
||||||
model = ForeignKeyTarget
|
model = ForeignKeyTarget
|
||||||
|
|
||||||
|
|
||||||
# Nullable ForeignKey
|
|
||||||
|
|
||||||
class NullableForeignKeySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
|
||||||
related_name='nullable_sources')
|
|
||||||
|
|
||||||
|
|
||||||
class NullableForeignKeySourceSerializer(serializers.ModelSerializer):
|
class NullableForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
depth = 1
|
depth = 1
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.tests.models import ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, NullableForeignKeySource
|
||||||
|
|
||||||
# ManyToMany
|
|
||||||
|
|
||||||
class ManyToManyTarget(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
|
|
||||||
class ManyToManySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
targets = models.ManyToManyField(ManyToManyTarget, related_name='sources')
|
|
||||||
|
|
||||||
|
|
||||||
class ManyToManyTargetSerializer(serializers.ModelSerializer):
|
class ManyToManyTargetSerializer(serializers.ModelSerializer):
|
||||||
|
@ -26,17 +16,6 @@ class ManyToManySourceSerializer(serializers.ModelSerializer):
|
||||||
model = ManyToManySource
|
model = ManyToManySource
|
||||||
|
|
||||||
|
|
||||||
# ForeignKey
|
|
||||||
|
|
||||||
class ForeignKeyTarget(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
target = models.ForeignKey(ForeignKeyTarget, related_name='sources')
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeyTargetSerializer(serializers.ModelSerializer):
|
class ForeignKeyTargetSerializer(serializers.ModelSerializer):
|
||||||
sources = serializers.ManyPrimaryKeyRelatedField()
|
sources = serializers.ManyPrimaryKeyRelatedField()
|
||||||
|
|
||||||
|
@ -49,14 +28,6 @@ class ForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||||
model = ForeignKeySource
|
model = ForeignKeySource
|
||||||
|
|
||||||
|
|
||||||
# Nullable ForeignKey
|
|
||||||
|
|
||||||
class NullableForeignKeySource(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
|
||||||
related_name='nullable_sources')
|
|
||||||
|
|
||||||
|
|
||||||
class NullableForeignKeySourceSerializer(serializers.ModelSerializer):
|
class NullableForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = NullableForeignKeySource
|
model = NullableForeignKeySource
|
||||||
|
|
Loading…
Reference in New Issue
Block a user