From 466a2b654d177b341859eefc8fb8207e498e8058 Mon Sep 17 00:00:00 2001 From: Jorge Date: Wed, 4 Aug 2021 15:56:55 -0400 Subject: [PATCH] Add name, name_exact and name_startswith filters to Feed --- .../migrations/0009_auto_20210804_1530.py | 43 +++++++++++++++++++ chris_backend/feeds/models.py | 20 +++++---- 2 files changed, 55 insertions(+), 8 deletions(-) create mode 100755 chris_backend/feeds/migrations/0009_auto_20210804_1530.py diff --git a/chris_backend/feeds/migrations/0009_auto_20210804_1530.py b/chris_backend/feeds/migrations/0009_auto_20210804_1530.py new file mode 100755 index 00000000..59ff04e8 --- /dev/null +++ b/chris_backend/feeds/migrations/0009_auto_20210804_1530.py @@ -0,0 +1,43 @@ +# Generated by Django 2.2.24 on 2021-08-04 19:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feeds', '0008_auto_20190114_1437'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='content', + field=models.TextField(blank=True), + ), + migrations.AlterField( + model_name='comment', + name='title', + field=models.CharField(blank=True, max_length=100), + ), + migrations.AlterField( + model_name='feed', + name='name', + field=models.CharField(blank=True, db_index=True, max_length=200), + ), + migrations.AlterField( + model_name='note', + name='content', + field=models.TextField(blank=True), + ), + migrations.AlterField( + model_name='note', + name='title', + field=models.CharField(blank=True, max_length=100), + ), + migrations.AlterField( + model_name='tag', + name='name', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/chris_backend/feeds/models.py b/chris_backend/feeds/models.py index 5eea4499..3013db57 100755 --- a/chris_backend/feeds/models.py +++ b/chris_backend/feeds/models.py @@ -8,7 +8,7 @@ class Feed(models.Model): creation_date = models.DateTimeField(auto_now_add=True) modification_date = models.DateTimeField(auto_now_add=True) - name = models.CharField(max_length=100, blank=True, default='') + name = models.CharField(max_length=200, blank=True, db_index=True) owner = models.ManyToManyField('auth.User', related_name='feed') class Meta: @@ -55,18 +55,22 @@ class FeedFilter(FilterSet): lookup_expr='gte') max_creation_date = django_filters.IsoDateTimeFilter(field_name="creation_date", lookup_expr='lte') + name = django_filters.CharFilter(field_name='name', lookup_expr='icontains') + name_exact = django_filters.CharFilter(field_name='name', lookup_expr='exact') + name_startswith = django_filters.CharFilter(field_name='name', + lookup_expr='startswith') class Meta: model = Feed - fields = ['id', 'name', 'min_id', 'max_id', 'min_creation_date', - 'max_creation_date'] + fields = ['id', 'name', 'name_exact', 'name_startswith', 'min_id', 'max_id', + 'min_creation_date', 'max_creation_date'] class Note(models.Model): creation_date = models.DateTimeField(auto_now_add=True) modification_date = models.DateTimeField(auto_now_add=True) - title = models.CharField(max_length=100, blank=True, default='') - content = models.TextField(blank=True, default='') + title = models.CharField(max_length=100, blank=True) + content = models.TextField(blank=True) feed = models.OneToOneField(Feed, on_delete=models.CASCADE, related_name='note') def __str__(self): @@ -74,7 +78,7 @@ def __str__(self): class Tag(models.Model): - name = models.CharField(max_length=100, blank=True, default='') + name = models.CharField(max_length=100, blank=True) color = models.CharField(max_length=20) feeds = models.ManyToManyField(Feed, related_name='tags', through='Tagging') @@ -108,8 +112,8 @@ def __str__(self): class Comment(models.Model): creation_date = models.DateTimeField(auto_now_add=True) - title = models.CharField(max_length=100, blank=True, default='') - content = models.TextField(blank=True, default='') + title = models.CharField(max_length=100, blank=True) + content = models.TextField(blank=True) feed = models.ForeignKey(Feed, on_delete=models.CASCADE, related_name='comments') owner = models.ForeignKey('auth.User', on_delete=models.CASCADE)