I have a simple Django Model to save registration id and IMEI of users using my Android app:
class Device(models.Model):
registration_id = models.CharField(max_length=500)
imei_id = models.CharField(max_length=500)
It has an accompanying view:
class DeviceCreateView(CreateView):
model = Device
form_class = DeviceForm
The view is referred to quite simply in urls.py like so:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', DeviceCreateView.as_view(), name='home'),
]
And there's a corresponding forms.py which has:
class DeviceForm(forms.ModelForm):
class Meta:
model = Device
fields = ("registration_id", "imei_id")
Lastly, this is the template to go with all that:
<form method="POST" action="{% url 'home' %}">
{% csrf_token %}
{{ form.as_p }}
<button>Submit</button>
</form>
This gives me a neat little web service to manually input the regis_id and the IMEI of the device, and store it in the database. But what I instead want is a way to directly post the regis_id and the IMEI from the client app to my Django model, instead of doing it manually. The client end isn't my task, I just have to do the server end. How do I change my web service such that it can "receive" the relevant value(s) from the client? This might be straightforward, but being a newbie, I'm struggling with figuring this out. Can anyone give me a simple example of how to do it?