orm - Basic Django Query -


simple scenario can't figure out how query it:

we have store model , transaction model. foreign key on transaction model relating store.

i want query list of: only stores have done at least one transaction day. other stores should excluded.


store.objects.filter(transaction__gt=0, transaction__date_created__gt='2016-06-01')

when tried former query, got long list back:

[<store: trialstore>, <store: trialstore>, <store: trialstore>, ... ] 

it's if it's listing instance of store each transaction. want list of each store has done @ least 1 transaction day.

right now, there's 1 store in database, should getting 1 result.

edit

store model:

class store(models.model):   status = models.integerfield(choices=status_choices, default=active_status)   legal_name = models.textfield(verbose_name='legal name')   mobile_number = phonenumberfield(blank=true)   email_address = models.emailfield(blank=true) 

transaction model:

class transaction(models.model):   store = models.foreignkey(store)   date_created = models.datetimefield(auto_now_add=true, verbose_name='created')   status = models.integerfield(choices=status_choices) 

you should use distinct():

store.objects.filter(transaction__gt=0,                      transaction__date_created__gt='2016-06-01').distinct()