python - Django accessing ForeignKey model objects -
let's have following:
class employee(models.model): firstname = models.charfield(max_length = 30) lastname = models.charfield(max_length = 30) class license(models.model): employee = models.foreignkey(employee) type = models.charfield(max_length = 30)
and in custom management command, i'm pulling in employee objects employees = employee.objects.all()
... how can access associated license objects each employee object? have seen questions talk using contenttype purpose, i'm confused on it's practical use. can provide example on how use contenttype (or solution) in context?
employee.license_set.all()
https://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects
Comments
Post a Comment