Skip to content

Instantly share code, notes, and snippets.

@specialunderwear
Last active April 22, 2019 13:19
Show Gist options
  • Save specialunderwear/73506a597c64ab58ce2e151d9407e028 to your computer and use it in GitHub Desktop.
Save specialunderwear/73506a597c64ab58ce2e151d9407e028 to your computer and use it in GitHub Desktop.
from django.db import models
class Bar(models.Model):
spam = models.EmailField()
class Foo(models.Model):
bars = models.ManyToManyField(Bar, through='ThroughFooBars')
class ThroughFooBars(models.Model):
foo = models.ForeignKey(Foo, models.DO_NOTHING)
bar = models.ForeignKey(Bar, models.DO_NOTHING)
order = models.PositiveIntegerField(default=0)
class Meta:
db_table = 'through_foo_bars'
unique_together = (('foo', 'bar'),)
ordering = ('order',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment