1👍
You haven’t defined the fk
properly:
class Foo(models.Model):
pass
class Bar(models.Model):
name = models.CharField()
foo = models.ForeignKey(Foo, related_name='bars', blank=True, null=True, default=None)
To deal with circular imports:
foo = models.ForeignKey('<app_name>.Foo', related_name='bars', blank=True, null=True, default=None)
1👍
You must use related_query_name in your query filter. By default in Django 1.8 it’s model name, so set custom related_query_name or change your code to this:
Foo.objects.filter(bar__name=xyz)
- [Answered ]-Django 1.10 Delete large cascade querySet
- [Answered ]-Django REST – create object with PrimaryKey
- [Answered ]-Django Rest Framework User and UserRole and Permission Handling using Token Authentication
- [Answered ]-Modifying manage.py for development and production
- [Answered ]-Django – How to move attribute to another model and delete it
Source:stackexchange.com