angularjs - How to get data from related tables like in django rest framework browsable API -
i need populate form through angularjs should data api. api should return data user table , data static tables (plan, country) related user table through foreign key.
serializers:
class countryserializer(serilizers.modelserializer): class meta: model = country queryset = country.objects.all() fields = ('id','name') class planserializer(serializers.modelserializer): class meta: model = plan queryset = plan.objects.all() fields = ('id','details') class userserializer(serializers.modelserializer): plan = planserializer() conutry = countryserializer() class meta: model = user fields = ('name','plan','role','country',)
my user model:
class user(models.model): name = models.charfield(max_length = 60) role = models.foreignkey(user_role, null = true, blank = true) plan = models.foreignkey(plan, null = true, blank = true) country = models.foreignkey(country, null = true, blank = true)
i make call userserializer
api angularjs, should return user's name, plan, role, country , list of other plans, country corresponding table.
basically need update plan, country user, , need have other plan/country details plan/country table can send put/patch request update it. similar django rest framework browsable api html form (for put) except use angularjs data server.
all want api picks data corresponding user gets additional data other static tables(plan,country tables) helpful update fields(like plan,country).
what you're trying achieve here (returning different types of objets in same response) not compliant idea of rest, it's unlikely "django-rest-framework" let that.
you should make 3 api calls here:
- 1 user
- 1 list of countries
- 1 list of plans
Comments
Post a Comment