I might not be understanding this fully, but what about A.objects.filter(type__mnemo__startswith="type1")?
On Thu, Jul 5, 2012 at 7:51 AM, Serg Shtripling <ser...@shtripling.com> wrote: > Hello, community! > Have anyone tried this: > class AType(models.Model): > #cut > mnemo = models.CharField(u'Mnemocode', max_length=31, null=True, > unique=True) > > class A(models.Model): > #cut > type = models.ForeignKey(AType, 'mnemo', verbose_name=u'A Type', > null=True) > > class B(models.Model): > #cut > type_mnemo = models.CharField(u'A Type', max_length=31, null=True, > blank=True) > Mnemos = {type1, type1__plus, type1__minus, type2, type2__plus,....} > Now I want to get all A records, having AType starts with "type1", eg: > "type1,type1__plus, type1__minus" > > r = A.objects.filter(type_id__startswith='type1') > And got: > TypeError: Related Field has invalid lookup: startswith > As a workaround, I've replaced A model with B model - I do not have a > relation, but query works as expected. > Q: 1)Is it OK, that A.type_id, not just A.type field is a Related Field? > q=AType.objects.all()[0] >>>> type(q.type) > <class 'main.models.AType'> >>>> type(q.type_id) > <type 'unicode'> > 2) Is there a more correct way to solve this issue? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/aV3iT_l4v1kJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- "The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde |_|0|_| |_|_|0| |0|0|0| (\__/) (='.'=)This is Bunny. Copy and paste bunny (")_(") to help him gain world domination. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.