Sorry i’m a beginner in django and python..i create a project and i’ve a models.py like this:
from django.db import models
class Shoes(models.Model):
type = models.CharField(max_length=30)
start_date = models.DateTimeField()
number = models.IntegerField()
def __unicode__(self):
return str(self.id)
class Meta:
verbose_name_plural = "Shoes"
class Bottom(models.Model):
type = models.CharField(max_length=30)
finish = models.BooleanField()
size = models.IntegerField()
def __unicode__(self):
return str(self.id)
class Meta:
verbose_name_plural = "Bottoms"
class Relation(models.Model):
shoes = models.OneToOneField(Shoes)
bottom = models.ForeignKey(Bottom)
class Meta:
verbose_name_plural = "Relations"
I want to serialize theese classes in json..sorry i need to understand where and how write the specific code to do it..
I wrote already a file views.py and a file.html to view a web page with table of theese objects, but now because i need to write a jquery function that allow to update the web page automatically when i add a new object, I think that we need to serialize the data in json before doing so.
Thanks and bear with me if I said something idiotic because i’m a really beginner in this field..
You want to serialize classes? You want to serialize objects! 🙂 In order to serialize Django objects you can use built-in mechanisms. Read this:
https://docs.djangoproject.com/en/dev/topics/serialization/
For example you can do this like this: