python - Access Users Model foreign Key -
i writing first django app wanting utilise built in user model map own custom model.
my application going manage users devices. this, have table called devices. wanting foreign key per device maps user model (so 1 user can have multiple devices).
my question is, how add mapping in model. thing?
class devices(model.model): deviceid = model.charfield(maxlength=10) owner = model.foreignkey(<user??>)
thanks in advance,
paul
class device(model.model): deviceid = model.charfield(maxlength=10) owner = model.foreignkey(user)
you should check standarts coding styles django coding style standarization
- use singular words classes
- begin class name capital letter
- begin class field non capital letter
- etc...
you should check oficial documentation django: foreign key
after model related via foreignkey
can following actions, if have device object in variable called dev
:
dev.owner # return user object, can access user fields dev.owner.username dev.owner.email
Comments
Post a Comment