I have the following site structure:
- Windows
- 98
- Subpage1
- Subpage2
- XP
- ....
- 7
- ....
- Mac
- 10.7
- Subpage1
- Subpage2
- 10.8
- ...
- 10.9
- Ubuntu
- 13.10
Each OS is a app and I want a extra model for each app which represents a cross reference. The reference can go to any page.
So pseudocode would look like this:
class Reference(models.Model):
title = models.CharField(_('title'), max_length=200)
links_to = models.ForeignKey(Windows | Mac | Ubuntu)
I found a view posts about generic relation, but I was not able to use the solutions for my problem.
A link to a good, easy to understand tutorial or any help would be great.
Thanks
Edit:
I thought this might work. But I just can access one property (slug) in this example and not the whole object:
from django.db import models
from itertools import chain
from otherapp.models import Geschaeftsfelder
from otherapp.models import Themenschwerpunkte
from otherapp.models import Themen
from django.utils.translation import ugettext as _
from common.fields import MarkdownTextField, translated_field
class Box(models.Model):
title = models.CharField(max_length=100)
headline_de = MarkdownTextField(verbose_name=_(u'Inhaltstext (dt.)'), blank=True)
geschaeftsfelder = Geschaeftsfelder.objects.values_list('slug', 'title')
themenschwerpunkte = Themenschwerpunkte.objects.values_list('slug', 'title')
themen = Themen.objects.values_list('slug', 'title')
result_list = chain(geschaeftsfelder, themenschwerpunkte, themen)
links_to = models.CharField(
max_length=200,
choices= result_list
)
Edit 2: I also tried a solution with generic content types:
When I add the following code to my Box model, I get a dropdown list with the right content types (themenschwerpunkte, geschaeftsfelder, ...).
But I'm still not able to create a link to a specific page.
# http://stackoverflow.com/questions/6335986/how-can-i-restrict-djangos-genericforeignkey-to-a-list-of-models?lq=1
limit = models.Q(app_label = 'geschaeftsfelder', model = 'geschaeftsfelder') | models.Q(app_label = 'geschaeftsfelder', model = 'themenschwerpunkte') | models.Q(app_label = 'geschaeftsfelder', model = 'themen')
content_type = models.ForeignKey(ContentType, limit_choices_to = limit)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
Edit 3:
Thank you very much for your answers and the time you invested but I'm going to use feinCMS instead of djangoCMS. This is much easier to understand for me and more suitable.