Sunday, September 25, 2016

How to populate a JqGrid in Django with data obtained from a query (queryset)

I am working on a small online shop with Django 1.9 and JqGrid

Here is a simplification of my models:

    class Addresses(models.Model):
        address = models.TextField(db_column='ADDRESS', max_length=2000)
        city = models.CharField(db_column='CITY', max_length=400, blank=True, null=True)
        postal_code = models.CharField(db_column='POSTAL_CODE', max_length=200, blank=True, null=True)
        state = models.CharField(Country, db_column='STATE', max_length=400, blank=True, null=True)
        country = models.ForeignKey(Country, db_column='COUNTRY_ID', null=True)

    class Customers(models.Model):
        name = models.CharField(db_column='NAME', max_length=400)
        nif = models.CharField(db_column='NIF', max_length=200, null=True, blank=True)
        email = models.CharField(db_column='EMAIL', max_length=255, unique=True)
        mobile_number = models.CharField(db_column='MOBILE_NUMBER', max_length=200, blank=True, null=True)
        phone_number = models.CharField(db_column='PHONE_NUMBER', max_length=200, blank=True, null=True)
        addresses = models.ManyToManyField(Addresses, through='CustomerAddresses')


    class CustomerAddresses(models.Model):
        id = models.AutoField(db_column='ID', primary_key=True)
        address_name = models.CharField(db_column='ADDRESS_NAME', max_length=100)
        customer = models.ForeignKey(Customers)
        address = models.ForeignKey(Addresses)


    class Orders(models.Model):
        order_number = models.IntegerField(db_column='ORDER_NUMBER', unique=True)
        customer = models.ForeignKey('Customers', db_column='CUSTOMER_ID')
        payment_date = models.DateTimeField(db_column='PAYMENT_DATE', blank=True, null=True)
        payment_method = models.CharField(db_column='PAYMENT_METHOD', max_length=400, blank=True, null=True)
        delivery_address = models.ForeignKey('Addresses', db_column='ORDER_DELIVERY_ADDRESS_ID', related_name='delivery_address', blank=True, null=True)


I want an edit page for a given Customer to look like this:



At the bottom, I want to display grids (JqGrid) inside jQuery tabs.

The Orders grid, should contain all the orders that are associated with the current Customer

    queryset = Orders.objects.filter(customer=customer_pk)

Idem, for the Addresses.

As you can see, I successfully created the tabs and grid, BUT the grids are not filled with the required data (queryset).

Could you help me understand how I should populate the grids with the data I want?

I am sorry if this question is not well explained. I am new in Django. If there is something you don't understand, please tell me.

Thanks

--
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/e7e9b341-f5e3-4010-bb63-78d4bec635ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment