0
Good evening, I was studying a bit of Rest framework on Jango and I developed a simple Api to consume with Angular went all right however my api I did is limited to
{
[
{
"id":1,
"name":"lima",
"phone","000000000",
"email","[email protected]",
"photo","localhost/members/profile/foto1.jpg"
},
{
"id":2,
"name":"Carlos",
"phone","000000000",
"email","[email protected]",
"photo","localhost/members/profile/foto2.jpg"
}
]
}
She was limited to this json structure but I wanted to do something more complete and a little more complex kk I’ll give an example here of how I wanted to:
{
[
"id": 1,
"User": {
"name":"João Vitor",
"phone":"000000000",
"email": "[email protected]",
"configuracoes": {
"aqui vem algumas configurações setadas pelo usuário
}
},
"pedidos": [
{
"Aqui vem uma lista de pedidos desse usuário que vai chegar através de outra aplicação
}
]
]
}
Consuming and manipulating the api using Angular I’m getting the problem right and how I’m going to create this more complex api there. I will leave the model file where I describe my api and then migrate that file.
This is the migrate file 0001
# Generated by Django 3.0.6 on 2020-05-28 14:57
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Member',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('surname', models.CharField(max_length=100)),
('phone', models.CharField(max_length=100)),
('email', models.EmailField(max_length=254)),
('addres', models.CharField(max_length=100)),
('photo', models.ImageField(upload_to='members_profile')),
],
),
]
And this is the model that generated this file:
from django.db import models
# Create your models here.
class Member(models.Model):
name = models.CharField(max_length=100)
surname = models.CharField(max_length=100)
phone = models.CharField(max_length=100)
email = models.EmailField()
addres = models.CharField(max_length=100)
photo = models.ImageField(upload_to='members_profile', blank=True, null=True )
def __str__(self):
return f'{self.name} {self.surname}'
Hi there. Share the models you are using that you need for your api you will have a new user object and finally configurations? Another thing, eliminate Migrations, having no associated error, it is not relevant to present here, it does not add value to your question. Another thing that got the impression, I may be wrong, is that you developed the client and now you are in the backend, take a look at the concept api-first https://dzone.com/articles/an-api-first-development-approach-1. It is possible to get the api as you want, but the right data structure will have to be created (models).
– Ernesto Casanova