Skip to content

Commit

Permalink
Add name, name_exact and name_startswith filters to Feed
Browse files Browse the repository at this point in the history
  • Loading branch information
jbernal0019 committed Aug 4, 2021
1 parent 5a50f13 commit 466a2b6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
43 changes: 43 additions & 0 deletions chris_backend/feeds/migrations/0009_auto_20210804_1530.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
20 changes: 12 additions & 8 deletions chris_backend/feeds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -55,26 +55,30 @@ 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):
return self.title


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')
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 466a2b6

Please sign in to comment.