Feincms content_type problem

61 views
Skip to first unread message

dobrysmak

unread,
Apr 20, 2012, 4:31:10 AM4/20/12
to django-...@googlegroups.com
Hi, i'm a feincms begginer and i have a quick question.

class Item(models.Model):
    content_type    = models.ForeignKey(ContentType)
    object_id          = models.PositiveIntegerField()
    content_object  = generic.GenericForeignKey("content_type", "object_id")

    article               = models.ForeignKey('Article')

how can i make the Item model to use raw_id_field for the content_type, or to display content_type's formset, in admin backend? 
and is there a way to limit choices ,in feincms, for the content_type choice list?

Cheers.

Matthias Kestenholz

unread,
Apr 21, 2012, 2:53:21 AM4/21/12
to django-...@googlegroups.com

Do something like this:

from feincms.admin.item_editor import FeinCMSInline

class ItemInline(FeinCMSInline):
raw_id_fields = ('content_type',)

class Item(models.Model):
feincms_item_editor_inline = ItemInline

# ... your model fields etc.

I think there's a better way to do this, though. There's no nice
widget for showing generic foreign keys to the user in Django
currently. You'll be much better off if you add different content
types for all other models you want to integrate in the CMS. Something
like this might work better (untested):


class ItemInline(FeinCMSInline):
raw_id_fields = ('item',)

class Item(models.Model):
feincms_item_editor_inline = ItemInline
class Meta:
abstract = True
def render(self, **kwargs):
return render_to_string([
'content/item/%s.html' % self.item.__class__.__name__,
'content/item/default.html'], {'content': self})


class Model1Item(Item):
item = models.ForeignKey(Model1)
class Meta:
abstract = True
Page.create_content_type(Model1)

class Model2Item(Item):
item = models.ForeignKey(Model2)
class Meta:
abstract = True
Page.create_content_type(Model2)

All you have to do is create a few templates in the content/item/
folder named model1.html, model2.html, default.html.


Regards,
Matthias

dobrysmak

unread,
Apr 24, 2012, 2:53:17 AM4/24/12
to django-...@googlegroups.com
Thanks !!
That's easier then i thought ;)

Cheers!
Reply all
Reply to author
Forward
0 new messages