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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -