Skip to content

Instantly share code, notes, and snippets.

@haplo
Created February 17, 2010 11:42
Show Gist options
  • Save haplo/306532 to your computer and use it in GitHub Desktop.
Save haplo/306532 to your computer and use it in GitHub Desktop.
Example usage for Django's get_by_natural_key
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]
@roma-075
Copy link

thx

@haplo
Copy link
Author

haplo commented Apr 15, 2024

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