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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.