Skip to content

Instantly share code, notes, and snippets.

@oinopion
Created February 5, 2012 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oinopion/1745211 to your computer and use it in GitHub Desktop.
Save oinopion/1745211 to your computer and use it in GitHub Desktop.
(cascade) % ./manage.py syncdb
Creating tables ...
Creating table ticket_a
Creating table ticket_b
Creating table ticket_c
Installing custom SQL ...
Installing indexes ...
No fixtures found.
(cascade) % ./manage.py shell
Python 2.7.2 (default, Jan 17 2012, 23:42:54)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from ticket.models import *
>>> a = A.objects.create()
>>> b = B.objects.create(just_a=a)
>>> c = C.objects.create(maybe_b=b)
>>> a = A.objects.all()[0]
>>> a.delete()
>>> c = C.objects.all()
>>> c
[]
from django.db import models
class A(models.Model):
pass
class B(models.Model):
just_a = models.ForeignKey(A)
class C(models.Model):
maybe_b = models.ForeignKey(B, null=True, blank=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment