Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide UUIDMixin in the models #15

Open
rambo opened this issue Jan 29, 2013 · 2 comments
Open

Provide UUIDMixin in the models #15

rambo opened this issue Jan 29, 2013 · 2 comments
Labels

Comments

@rambo
Copy link

rambo commented Jan 29, 2013

Something like this:

class UUIDMixin(models.Model):
    uuid = UUIDField(auto=True)

    class Meta:
        abstract = True

And it could be used like this:

from uuidfield.models import UUIDMixin
class MyClass(UUIDMixin, models.Model):
    title = models.CharField(max_length=200)

    def __unicode__(self):
        return self.title
@rambo
Copy link
Author

rambo commented Jan 30, 2013

Also one mixin for using UUID as the primary key.

class UUIDPrimaryMixin(models.Model):
    uuid = UUIDField(auto=True, primary_key=True)

    class Meta:
        abstract = True

@rambo
Copy link
Author

rambo commented Jan 31, 2013

And one more mixin I made for myself:

class UUIDLoaderMixin(object):
    def get_object(self):
        return get_object_or_404(self.model, uuid=self.kwargs['uuid'])

Used:

class FooDetailView(UUIDLoaderMixin, DetailView):
    model = Foo

@luto luto added the feature label Nov 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants