0

for example I have two models

class User(models.Model):
    username = models.CharField(max_length=100,unique=True)
    password = models.CharField(max_length=100,null=False,blank=False)

class Car(models.Model):
    user = models.ForeignKey(User)
    car_name = models.CharField(max_length=100,null=True,blank=True)
    car_price = models.CharField(max_length=100,null=True,blank=True)

each user can have multiple cars.

I would like to add car name and price by making post request something like

curl -X POST -d "car_name=BMW&car_price=$0.5M" -u username:userpasswd
karthikr
  • 97,368
  • 26
  • 197
  • 188

1 Answers1

1

There is currently no other way that using a third party app to create a REST API in Django. This is something not natively supported in Django.

But Tastypie and Django Rest Framework are two very good third apps, there's nothing wrong to use them. They both have good documentation and there exists lots of posts talking about them.

Once you set your REST API using one of these apps, you can use CURL (like in your example) or Python requests to make post/get/.. requests.

David Dahan
  • 10,576
  • 11
  • 64
  • 137
  • http://stackoverflow.com/questions/24122231/foriegnkey-field-serializer-in-django-rest-framework I'm having problem with DRF, can you plz help me – Nancy kamra Jun 09 '14 at 19:33
  • 2
    How is building a REST API not natively supported by Django? It's only parsing the data and answering with json. I don't see a reason _not_ to use a framework like DRF and Tastypie since they do a lot of work for you. – Denis Cornehl Jun 11 '14 at 07:02