Browse Source

fix model mixins not working without django_scopes

main
Julia Luna 3 years ago
parent
commit
22a1dcd3ff
Signed by: xenua
GPG Key ID: 6A0C04FA9A7D7582
  1. 2
      setup.py
  2. 10
      xenua/django/models.py

2
setup.py

@ -8,7 +8,7 @@ Anything that I repeatedly implement probably ends up in here. @@ -8,7 +8,7 @@ Anything that I repeatedly implement probably ends up in here.
setup(
name='xenua_tools',
version='0.1.0',
version='0.1.1',
description='Miscellaneous functions that are sometimes helpful',
long_description=long_description,
long_description_content_type='text/plain',

10
xenua/django/models.py

@ -4,8 +4,8 @@ from django.utils.crypto import get_random_string @@ -4,8 +4,8 @@ from django.utils.crypto import get_random_string
try:
from django_scopes import scopes_disabled
except ImportError:
from xenua.decorators import no_op as scopes_disabled
scopes_disabled = False
class RandomSlugMixin(models.Model):
"""
@ -29,14 +29,12 @@ class RandomSlugMixin(models.Model): @@ -29,14 +29,12 @@ class RandomSlugMixin(models.Model):
if not self.slug:
self.slug = self.generate_new_slug()
@scopes_disabled()
def generate_new_slug(self):
slug = get_random_string(self.slug_length, self.slug_chars)
if self.__class__.objects.filter(slug=slug).exists():
return self.generate_new_slug()
return slug
@scopes_disabled()
@property
def slugs_available(self):
return self.slug_count_total - self.__class__.objects.count()
@ -49,6 +47,10 @@ class RandomSlugMixin(models.Model): @@ -49,6 +47,10 @@ class RandomSlugMixin(models.Model):
def slug_length(self):
return self.__class__._meta.get_field('slug').max_length
if scopes_disabled:
generate_new_slug = scopes_disabled(generate_new_slug)
slugs_available = scopes_disabled(slugs_available)
class RandomSlugPKMixin(RandomSlugMixin):
slug = models.CharField(max_length=6, unique=True, primary_key=True)

Loading…
Cancel
Save