Created
October 14, 2014 11:41
-
-
Save daddz/0eaffdb22fb5838f6c91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Foo(Model): | |
bars = ManyToManyField(Bar, related_name='foos', blank=True, null=True) | |
class Bar(Model): | |
name = CharField(unique=True) | |
# The process I know currently: | |
foo = Foo() | |
foo.save() | |
bar1 = Bar.objects.create(name='bar1') | |
bar2 = Bar.objects.create(name='bar2') | |
foo.bars.add(bar1) | |
foo.bars.add(bar2) | |
# What I would like to do | |
foo = Foo(bars=['bar1', 'bar2']) | |
foo.save() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment