class Entry( models.Model ): user = models.ForeignKey( User, related_name = 'user_relation' ) category = models.ForeignKey( Category, related_name = 'category_relation' ) title = models.CharField( max_length = 64 ) entry_text = models.TextField() deleted_datetime = models.DateTimeField() kwargs = { # you can set common filter params here } # will return entries which don't have a deleted_datetime if exclude_deleted: kwargs[ 'deleted_datetime__isnull' ] = True # will return entries in a specific category if category is not None: kwargs[ 'category' ] = category # will return entries for current user if current_user_only: kwargs[ 'user' ] = request.user # will return entries where titles match some search query if title_search_query != '': kwargs[ 'title__icontains' ] = title_search_query # apply all filters and fetch entries that match all criteria entries = Entry.objects.filter( **kwargs )
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Django kwargs (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Close comments after a set t... in python django comments
» lighttpd.conf update for use... in lighttpd python django
» For pkit in python django
» Implement automatic comment ... in python django comments anti-spam moderation
» LightTPD subdomain rewrite, ... in lighttpd python subdomain fcgi django mod_rewrite
» Django Q objects in python django q
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails