If have a model for companies. These companies have an attribute employment_set
, because workers are assigned to companies via the employment relation. How can I query all employees for a given company?
The model for the employements look like this:
class Employment(
SoftDeletableModel,
TimeStampedModel,
models.Model
):
company = models.ForeignKey(Company, on_delete=models.CASCADE)
employee = models.ForeignKey(UserWorkerProfile)
employed_by = models.ForeignKey(UserOwnerProfile)
I tried using company.employment_set.values("employee")
, but this returns a strange activatorquery set. Is there a way to return the normal queryset? Or is values()
already the correct method?
Edit: To eloborate a little more: I want to end up with a queryset containing all the UserWorkerprofile model instances.
In the documentation for values()
it says:
Returns a QuerySet that returns dictionaries, rather than model instances, when used as an iterable.
and I want exactly a queryset of model instances.