-
Notifications
You must be signed in to change notification settings - Fork 2
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
Stb#537 Fix field types determination for Search class #315
Conversation
ae68ce2
to
e3b2899
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proposal to redesign some code to OOP style
search/search.py
Outdated
@@ -46,6 +46,20 @@ def trigram_search(query: str, queryset, fields: List[str]): | |||
return queryset.annotate(similarity=trigram_query).order_by('-similarity') | |||
|
|||
|
|||
def field_type(model, field): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to now we had convenient to use verbs as the first word of a function name.
So, let's call it get_field_type
or change this convenient.
The both is ok for me, but convenient preserving should just cheaper.
Decide it plz
search/search.py
Outdated
@@ -46,6 +46,20 @@ def trigram_search(query: str, queryset, fields: List[str]): | |||
return queryset.annotate(similarity=trigram_query).order_by('-similarity') | |||
|
|||
|
|||
def field_type(model, field): | |||
"""Determine a type name of Django field.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'll be true OOP to create smth like this:
class FieldMeta:
"""Django Model's field metadata."""
TEXT_TYPES = ['CharField', 'TextField']
def __init__(model, field: str):
self.model = model
self.field = field
def type() -> str:
# field_type() function code here
...
def is_text() -> bool:
return self.type() in TEXT_TYPES
If you agree with it, pdd subtask would be good
Related to fidals/stroyprombeton#537