What do ReferenceField
stores. I mean does it store ObjectID
(or in my case user_id
, as it is primary_key
for User model). How can I access all the attributes of User model through unit_user as we do with the Foreignkey in Django
class User(Document):
user_id = IntField(primary_key=True)
user_name = StringField(max_length=100)
user_email = EmailField()
class MasterUnit(Document):
unit_id = IntField(primary_key=True)
unit_name = StringField(max_length=100)
unit_user = ReferenceField('User')
I am using POST method for posting data through my api:
class MasterUnitList(View):
def get(self, request):
masterunit = MasterUnit.objects.all().to_json()
data = json.loads(masterunit)
return JsonResponse(data, safe=False)
def post(self, request):
data = json.loads(request.body)
masterunit = MasterUnit(**data)
masterunit.save()
return JsonResponse(data, safe=False)
My urls.py is
path('api/unit', MasterUnitList.as_view(), name='MasterUnitList'),
path('api/unit/<int:pk>', MasterUnitDetail.as_view(), name='MasterUnitDetail'),
I am using httpie
http POST http://127.0.0.1:8000/api/unit unit_id=1 unit_name="Nokia" unit_user="?"
What do I pass in unit_user
field?