python - django queryset excluding rows that are referenced in a foreign table -


part of app consists of displaying statuses @ top of newsfeed. here have status model

class status(models.model):     user = models.foreignkey(user)     description = models.charfield(max_length = 600, blank = false)     created_at = models.datetimefield(auto_now_add = true, editable = false)     image = models.imagefield(upload_to = 'images/statuspics/%y/%m/%d', blank = true, null = true)     utility = models.foreignkey(utility)     numlikes = models.integerfield(default = 0)      class meta:         ordering = ["-created_at"]         # change plural form         verbose_name_plural = "statuses" 

i have responses, way of indicating how post responded to, , status announces it.

class response(models.model):     post = models.foreignkey(post, null = true, blank = true)     status = models.foreignkey(status, null = true, blank = true)     status_level = models.integerfield(         blank = true,         choices = status_choices,         default = 1)     created_at = models.datetimefield(auto_now_add = true, editable = false) 

basically want display statuses don't have responses corresponding it. think need use exclude() in views i'm not entirely sure how use in case.

can try status.objects.exclude(response__isnull=true)? it's reverse lookup on model status on response.

django doc isnull.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -