Django spanning relationships -
i've read documentation still coming errors. have users placing orders catalog objects. i'd create query returns users have order containing specific catalog item.
here models:
class catalog(models.model): name = models.charfield(max_length=100) cost = models.integerfield() def __unicode__(self): homecoming self.name class annual(models.model): catalog = models.onetoonefield(catalog, blank=true, null=true, related_name='annual_products') year_id = models.integerfield(max_length=4) start_date = models.charfield(max_length=10) end_date = models.charfield(max_length=10) date = models.datetimefield(auto_now_add=true, blank=true) def __unicode__(self): homecoming unicode(self.year_id) class order(models.model): user = models.foreignkey(user, related_name='who_ordered') select = models.manytomanyfield(catalog, related_name='annuals_ordered', blank=true, null=true) def __unicode__(self): homecoming unicode(self.user)
here query i've been trying:
catalog.objects.filter(order__select__annual='2014')
if need users, should start users. also, need filter on specific field in annual, ie year_id.
user.objects.filter(order__select__annual__year_id=2014)
django django-orm
No comments:
Post a Comment