public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
(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
[]
models.py
Python
1 2 3 4 5 6 7 8 9 10
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.