uche
uche

Reputation: 85

Django-views Custom filter

If having different books stored in django database, each book has a date in which it was added to the database. Is their a way of filtering books written by a certain author that was within a date range only using django views?

Upvotes: 0

Views: 684

Answers (1)

Lucas03
Lucas03

Reputation: 2347

Not sure what you mean by only django views, I assume you want to use querysets. Your question is poorly written - read this.

class Book(models.Model):
    title = models.CharField(max_length=200)
    date = models.DateTimeField()
    author = models.ForeignKey(Author)


class Author(models.Model):
    name = models.CharField(max_length=200)

And Queryset would be something like this.

books = Book.objects.filter(author__name=authors_name, 
                            date__range=["2011-01-01", "2011-01-31"])

Upvotes: 1

Related Questions