Skip to content

Instantly share code, notes, and snippets.

@0atman
Created February 26, 2013 15:06
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 0atman/5039091 to your computer and use it in GitHub Desktop.
Save 0atman/5039091 to your computer and use it in GitHub Desktop.
A generic grouping, other models m2m this.
class Group(models.Model):
"""
A generic grouping, other models m2m this.
"""
parent = models.ForeignKey('self', null=True, blank=True, related_name="children")
slug = models.SlugField(max_length=100, help_text="The slug field.", default="")
name = models.CharField(max_length=100)
def __unicode__(self):
return u"%s/%s" % (
(lambda g: g.parent if g.parent else "")(self),
self.slug
)
@0atman
Copy link
Author

0atman commented Feb 26, 2013

unicode() returns easy to read names like:

/parent/child

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment