#4667: [newforms-admin] add edit_inline support for generic relations
----------------------------------------------+-----------------------------
Reporter: Honza Král <[EMAIL PROTECTED]> | Owner: adrian
Status: new | Component: Admin interface
Version: newforms-admin | Keywords: edit_inline
generic content_type
Stage: Unreviewed | Has_patch: 1
----------------------------------------------+-----------------------------
I have a model that looks like (working example)
{{{
from django.db import models
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
class Dependency( models.Model ):
target_ct = models.ForeignKey( ContentType,
related_name='dependency_for_set' )
target_id = models.IntegerField()
target = generic.GenericForeignKey( 'target_ct', 'target_id' )
source_ct = models.ForeignKey( ContentType,
related_name='dependent_on_set' )
source_id = models.IntegerField()
source = generic.GenericForeignKey( 'source_ct', 'source_id' )
}}}
and I want to be able to edit it inline with other models, but the current
implementations only support edit_inline for foreign key relations. With
the attached patch I can do something like this:
{{{
from django.contrib import admin
class SomeModel( models.Model ):
text = models.TextField()
class SomeModelOptions( admin.ModelAdmin ):
inlines = [ admin.TabularInline( Dependency,
name='source_ct:source_id', formset=generic.GenericInlineFormset ), ]
admin.site.register( SomeModel , SomeModelOptions )
}}}
The patch is very rough, but working (tested adding and editing).
I have some questions for the authors (I will post it to django-dev):
* InlineFormset.rel_name is not really applicable in this case, what
would be best to use as a prefix (the value in tha patch - {{{'aaa'}}} is
far from ideal ;) )
* I moved some of the functionality to FormSet (add_fk), to allow for
custom binding between objects and use
{{{content_type_field:object_id_field}}} as the foreign key name to pass
that information. I feel that its not the most elegant solution, could
anybody help me out here with some ideas?
btw. Great work, Joseph Kocherhans, your implementation of edit_inline
really made this easy for me, thanks.
--
Ticket URL: <http://code.djangoproject.com/ticket/4667>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---