How to build an json object that contain objects class and dictionary.

2010-02-10 Thread manixor
Hello all,

   I need to send with HttpResponse an json object. I need to have
there more then one objects class(myclass.objects.all()) and a
dictionary. To have only objects I can do like this:
ob1 = cl1.objects.all()
ob2 = cl2.objects.all()
all_ob = list(ob1)
all_ob +=list(ob2)
return HttpResponse(serializers.serialize('json',  all_ob),
mimetype='application/json')

So my issue is to send on the same HttpResponse one dic too.
I tried like this:
env = {}
env['a'] = 'b'
all_ob +=list(env)  ...but not succed
or like this:
all_ob +=list(simplejson.dumps(env)) ...not succed

Somebody can give me other solution, that on an ajax request(jquery)
to have on callback objects class and a dictionary.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Delete a data row that is inherit by another one.

2010-02-14 Thread manixor
Hy, how can I check if a field is inherit by another one. If I delete
that field, it delete cascade, the foreign data too.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Ajax request, json object, fields with instance of inherits class converted in regular string

2010-02-19 Thread manixor
Hello all, I have a really big problem with ForeignKey Models. I will
try to emplain my problem:
I have a class like this:

class Day(models.Model):
name= models.CharField(_('Name'), max_length=32,
unique=True)
description = models.TextField(_('Description'),
max_length=1024, blank=True, null=True)

and one more:
class Week(models.Model):
name= models.CharField(_('Name'), max_length=32,
unique=True)
description = models.TextField(_('Description'),
max_length=1024, blank=True, null=True)
monday  = models.ForeignKey(Day, verbose_name=_('Monday'),
blank=True, null=True, related_name='mondays')

In my day table I have:
name = "Always"
description ="aaa"
name = "Never"
description ="bbb"

In my week table I have:
name = "Something"
description ="fff"
monday = 1

My problem is with the instance of the Day class in the monday field.
1 is the pk of the row with name "Always"

In view I can do like this:
ob = Week.object.all()
for o in ob:
o.monday.name
and I will get "Always" instead of 1 (pk)

OK, but, I need to send back to an ajax request this week object, with
a json object, and I do:
data = serializers.serialize("json", ob)

The very big problem is, when I loop into object on template, in the
monday field is not enymore the Day instance, but the string 1. How
can I convert to an json object the week object, and to keep the
instance of the inherits class, or how can I modify the ForeignField
model, to point to another field, like name in my case and not to the
pk, which is an integer in my case?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.