So , I have this 2 models:
class Site(models.Model):
...
...
and another one:
class SiteInfo(models.Model):
...
...
site = models.ForeignKey(Site)
Is there a way to get the Sites that have no entry in the SiteInfo ?
Django automatically creates an index for all models. ForeignKey columns. From Django documentation: A database index is automatically created on the ForeignKey .
To handle One-To-Many relationships in Django you need to use ForeignKey . The current structure in your example allows each Dude to have one number, and each number to belong to multiple Dudes (same with Business).
What is ForeignKey in Django? ForeignKey is a Field (which represents a column in a database table), and it's used to create many-to-one relationships within tables. It's a standard practice in relational databases to connect data using ForeignKeys.
Site.objects.filter(siteinfo__isnull=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With