Hi there, I don't know if I put the right title, so here is what I'm stuck with:
I have this model:
class Foo(models.Model):
name = models.CharField(...)
this one:
class Bar(models.Model):
name = models.CharField(....)
And their connection:
class FooBar(models.Model):
foo = models.ForeingKey(Foo, related_name='bars')
bar = models.ForeingKey(Bar, related_name='foos')
some_other_value = .....
And wanted to know how can I(if possible) do something that has the same result as this code:
f = Foo.objects.get(name='some foo')
b = Bar.objects.get(name='nice bars')
my_nice_bars = f.bars.filter(bar = b)
but without having to do the "b = Bar.objects.get(name='nice bars')" like this:
f = Foo.objects.get(name='some foo')
my_nice_bars = f.bars.get_by_name('nice bars')
Or even do a more complex query then "get_by_name".
Can I add this new query to the Foo.bars stuff?
I tried the
QueryManager from
django-model-utils, and added a new query to
Bar, but this couldn't be used in
Foo.bars