Skip to content

Issues with ForeignKey on 'self' #2

@braskin

Description

@braskin

The setup:

class QUser(models.Model):
username = models.CharField(max_length=30, unique=True)
objects = CacheBotManager()

class QInternalMessage(models.Model):
subject = models.CharField(max_length=120)
parent_msg = models.ForeignKey('self', related_name='next_message', null=True, blank=True, )
recipient = models.ForeignKey(QUser, null=True, blank=True, related_name='messages_received', db_index=True)
objects = CacheBotManager()

This hits an infinite loop...
rp = QInternalMessage.objects.select_related('parent_msg').get(id=1)
rp.subject='frick'
rp.save()

This hits an exception here: /cachebot/queryset.py in _get_related_models:
related_models.add((rev_reversemapping[attname], related.model))

rs = QInternalMessage.objects.cache().filter(recipient=user1)
for r in rs.all():
print r.subject

Anyone out there deal with this issue yet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions