Add on_delete atrributes to test models foreignkeys

pull/335/head
= 5 years ago
parent 24706f50d4
commit 73706fa6bb
  1. 6
      examples/starwars/models.py
  2. 6
      graphene_django/tests/models.py

@ -5,7 +5,7 @@ from django.db import models
class Character(models.Model):
name = models.CharField(max_length=50)
ship = models.ForeignKey('Ship', blank=True, null=True, related_name='characters')
ship = models.ForeignKey('Ship', on_delete=models.CASCADE, blank=True, null=True, related_name='characters')
def __str__(self):
return self.name
@ -13,7 +13,7 @@ class Character(models.Model):
class Faction(models.Model):
name = models.CharField(max_length=50)
hero = models.ForeignKey(Character)
hero = models.ForeignKey(Character, on_delete=models.CASCADE)
def __str__(self):
return self.name
@ -21,7 +21,7 @@ class Faction(models.Model):
class Ship(models.Model):
name = models.CharField(max_length=50)
faction = models.ForeignKey(Faction, related_name='ships')
faction = models.ForeignKey(Faction, on_delete=models.CASCADE, related_name='ships')
def __str__(self):
return self.name

@ -15,7 +15,7 @@ class Pet(models.Model):
class FilmDetails(models.Model):
location = models.CharField(max_length=30)
film = models.OneToOneField('Film', related_name='details')
film = models.OneToOneField('Film', on_delete=models.CASCADE, related_name='details')
class Film(models.Model):
@ -37,8 +37,8 @@ class Reporter(models.Model):
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
reporter = models.ForeignKey(Reporter, related_name='articles')
editor = models.ForeignKey(Reporter, related_name='edited_articles_+')
reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE, related_name='articles')
editor = models.ForeignKey(Reporter, on_delete=models.CASCADE, related_name='edited_articles_+')
lang = models.CharField(max_length=2, help_text='Language', choices=[
('es', 'Spanish'),
('en', 'English')

Loading…
Cancel
Save