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":"mail@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
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)
email = models.EmailField(max_length=100, default='mail@example.com',blank=False)
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
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7ed5caaf-7140-4b1f-a490-916a7c67d45d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment