mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-24 18:44:08 +03:00
96c09ac439
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
35 lines
755 B
Python
35 lines
755 B
Python
from django.db import models
|
|
|
|
|
|
class Character(models.Model):
|
|
name = models.CharField(max_length=50)
|
|
ship = models.ForeignKey(
|
|
"Ship",
|
|
on_delete=models.CASCADE,
|
|
blank=True,
|
|
null=True,
|
|
related_name="characters",
|
|
)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Faction(models.Model):
|
|
name = models.CharField(max_length=50)
|
|
hero = models.ForeignKey(Character, on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Ship(models.Model):
|
|
class Meta:
|
|
ordering = ["pk"]
|
|
|
|
name = models.CharField(max_length=50)
|
|
faction = models.ForeignKey(Faction, on_delete=models.CASCADE, related_name="ships")
|
|
|
|
def __str__(self):
|
|
return self.name
|