Created
February 5, 2012 12:28
-
-
Save oinopion/1745211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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