Hi group ;-)
I have a little challenge.
We have a frontend angular api. Wich sinds data to my django backend from an input form.
And Contact in the frontend How to just my serializer / models file right so the contact data is in my database?
contact?: {
name: string;
email: string;
phone: string;
}
What gets forwarded to my backend?
{"id":189267,"name":"asdf","address":"asdf","description":"asdf","totalSpots":"0","spotsTaken":"0","location":"0,0","contact":{"name":"asdf","email":"
ma...@email.com","phone":"1111111111"}}
this part is sending the data and arrives in the database.√
{"id":189267,"name":"asdf","address":"asdf","description":"asdf","totalSpots":"0","spotsTaken":"0","location":"0,0",
This part is my challenge and I made this ajustment in my models.py file and serialisers.py
"contact":{"name":"asdf","email":"
ma...@email.com","phone":"1111111111"}}
What are the files?
the angular file:
export interface IWorkPlace {
id: string;
name: string;
address: string;
description: string;
totalSpots: number;
spotsTaken: number;
location: [number, number];
contact?: {
name: string;
email: string;
phone: string;
}
}
my models.py
name = models.CharField(max_length=250)
address = models.CharField(max_length=250)
description = models.CharField(max_length=250)
totalSpots = models.CharField(max_length=250)
spotsTaken =models.CharField(max_length=250, blank=True)
image = models.ImageField(upload_to='workplace_image', blank =True)
location = models.CharField(max_length=250)
name = models.CharField(max_length=150)
phone = models.CharField(max_length=14 ,default='1111111111"', blank=False)
my serializer
class Workspace_bookingSerializer(serializers.ModelSerializer):
class Meta:
model = Workspace_booking
fields = ( 'id','name','address','description','totalSpots','spotsTaken','location','name','email','phone')
Sincere!
Tim