Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for different field names #12

Closed
johnwoltman opened this issue Dec 28, 2012 · 5 comments
Closed

Support for different field names #12

johnwoltman opened this issue Dec 28, 2012 · 5 comments

Comments

@johnwoltman
Copy link

The interface doesn't work when the ContentType-related fields aren't object_id. Is there a way to integrate genericadmin into an existing a codebase? For my model, I've been using target_id as the field for storing IDs of other objects in my ContentType-enabled models.

@murdav
Copy link

murdav commented Oct 14, 2013

Dear All,
I have the same question.

Mine are:
layer_content_type = models.ForeignKey(ContentType)
layer_id = models.PositiveIntegerField()
layer = generic.GenericForeignKey('layer_content_type', 'layer_id')

And in the admin this won't work:

class MyAdminClassGenericAdminModelAdmin):
****
ct_field = 'layer_content_type'
ct_fk_field = 'layer_id'

ideas?

@jschrewe
Copy link
Collaborator

I think (it's been some time since I last looked at this) that the field id is hardcoded in the javascript and the trouble with making this more flexible is that exchanging data between Django and javascript files sucks quite a bit.

So, I hope I can take a look at this a bit more tomorrow but if you want to try yourself and just need something that works, try to change the javascript file so that it finds the right field.

HTH
Jan

@murdav
Copy link

murdav commented Oct 14, 2013

Thanks for replying and point me.
Django-genericadmin is the best that Internet is offering to manage ContentType in Django!
It took me 3 minutes and it was working. Thank you!
I'm going to look at the JS and I will report to you tomorrow!

@jschrewe
Copy link
Collaborator

Took a little longer then expected, but the newest version will a) figure out all generic foreign keys on the model by itself (yes, it does work with multiple generic fks) and b) also work with all names provided.

If you want to configure manually which fields the javascript will handle, you can set the generic_fk_fields option on the admin. It should take the form:

class MyAdmin(GenericAdminModelAdmin):
    generic_fk_fields = [{
        'ct_field': <field_name_for_contenttype_fk>,
        'fk_field': <field_name_for_object_id>,
    }]

For more then one GenericForeignKey add one more dict to the list.

I'm not sure if this interferes with the inline admin options.

@jschrewe
Copy link
Collaborator

So, as far as I can tell version 0.5 (yay, it's even on Pypi) works with an unlimited number of generic fields and completely supports inline admins.

If you find problems, I'd appreciate reopening this issue or a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants