-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from eaudeweb/keyword-fixes
Keyword fixes
- Loading branch information
Showing
11 changed files
with
188 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
|
||
|
||
class LowerCharField(models.CharField): | ||
|
||
def pre_save(self, model_instance, add): | ||
value = getattr(model_instance, self.attname, None) | ||
if value: | ||
value = value.lower() | ||
setattr(model_instance, self.attname, value) | ||
return value | ||
else: | ||
return super().pre_save(model_instance, add) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 2.2.9 on 2020-02-06 13:46 | ||
|
||
import app.fields | ||
from django.db import migrations | ||
from django.db.models import F | ||
from django.db.models.functions import Lower | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
Keyword = apps.get_model("app", "Keyword") | ||
db_alias = schema_editor.connection.alias | ||
Keyword.objects.using(db_alias).annotate( | ||
value_lower=Lower('value') | ||
).update(value=F('value_lower')) | ||
|
||
|
||
def reverse_func(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app', '0027_rename_winner_to_award'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards_func, reverse_func), | ||
migrations.AlterField( | ||
model_name='keyword', | ||
name='value', | ||
field=app.fields.LowerCharField(max_length=50, unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.9 on 2020-02-07 09:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app', '0028_make_keywords_lowercase'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='tender', | ||
name='keywords', | ||
field=models.ManyToManyField(blank=True, related_name='tenders', to='app.Keyword'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.