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

In admin, wrapped in a layer of "re.compile('...')" on every save #34

Open
mverleg opened this issue Sep 25, 2018 · 2 comments
Open

In admin, wrapped in a layer of "re.compile('...')" on every save #34

mverleg opened this issue Sep 25, 2018 · 2 comments

Comments

@mverleg
Copy link

mverleg commented Sep 25, 2018

I have made the regex field available in the Django admin panel, but every time I save it, it wraps the field in re.compile('...').

path = RegexField(max_length=128, blank=False, null=False)

I end up with something like:

re.compile('re.compile("re.compile(\'/post/\\\\\\\\d/\')")')

It could be that I'm using this incorrectly somehow, but I'm not sure what's wrong.

@edwelker
Copy link

edwelker commented Jan 4, 2019

+1

@edwelker
Copy link

edwelker commented Jan 4, 2019

Work-around:

from django.forms.fields import CharField
from regex_field.fields import RegexField as BrokenRegexField

class FixedRegexField(CharField):
    def prepare_value(self, value):
        try:
            return value.pattern
        except AttributeError:
            return value

class RegexField(BrokenRegexField):
    def formfield(self, **kwargs):
        defaults = {'form_class': FixedRegexField}
        defaults.update(kwargs)
        return super().formfield(**defaults)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants