Created
February 17, 2010 11:42
-
-
Save haplo/306532 to your computer and use it in GitHub Desktop.
Example usage for Django's get_by_natural_key
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 AuthorManager(models.Manager): | |
def get_by_natural_key(self, first_name, last_name) | |
return self.get(first_name=first_name, last_name=last_name) | |
class Author(models.Model): | |
first_name = models.CharField(max_length=50) | |
last_name = models.CharField(max_length=50) | |
objects = AuthorManager() | |
def __unicode__(self): | |
return u'%s %s' % (self.first_name, self.last_name) | |
def get_natural_key(self): | |
return [self.first_name, self.last_name] |
thx
You're welcome, glad you found it useful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx