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.

Reply via email to